summaryrefslogtreecommitdiff
path: root/ext/socket/rubysocket.h
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-18 14:13:22 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-18 14:13:22 +0000
commit971ef822679dfa6ee63ff83a47b4e4d1aa60d146 (patch)
treeab244ae10e099db0f04596f1e5f0bfe317146b18 /ext/socket/rubysocket.h
parente86a90420d06f613cf597f266abb5429aa2d6b43 (diff)
* ext/socket: Avoid unnecessary ppoll/select on Linux.
Patch by Eric Wong. [ruby-core:57950] [Bug #9039] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44643 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/rubysocket.h')
-rw-r--r--ext/socket/rubysocket.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/ext/socket/rubysocket.h b/ext/socket/rubysocket.h
index c74fb32..2f8ce9d 100644
--- a/ext/socket/rubysocket.h
+++ b/ext/socket/rubysocket.h
@@ -386,4 +386,20 @@ NORETURN(void rsock_sys_fail_sockaddr(const char *, struct sockaddr *addr, sockl
NORETURN(void rsock_sys_fail_raddrinfo(const char *, VALUE rai));
NORETURN(void rsock_sys_fail_raddrinfo_or_sockaddr(const char *, VALUE addr, VALUE rai));
+/*
+ * It is safe on Linux to attempt using a socket without waiting on it in
+ * all cases. For some syscalls (e.g. accept/accept4), blocking on the
+ * syscall instead of relying on select/poll allows the kernel to use
+ * "wake-one" behavior and avoid the thundering herd problem.
+ * This is likely safe on all other *nix-like systems, so this whitelist
+ * can be expanded by interested parties.
+ */
+#if defined(__linux__)
+static inline int rsock_maybe_fd_writable(int fd) { return 1; }
+static inline void rsock_maybe_wait_fd(int fd) { }
+#else /* some systems (mswin/mingw) need these. ref: r36946 */
+# define rsock_maybe_fd_writable(fd) rb_thread_fd_writable((fd))
+# define rsock_maybe_wait_fd(fd) rb_thread_wait_fd((fd))
+#endif
+
#endif