From d8bbb5eda83f92bfa6045bc5165f7578e524a2f5 Mon Sep 17 00:00:00 2001 From: normal Date: Fri, 29 May 2015 02:24:18 +0000 Subject: socket: avoid redundant fcntl on Linux * ext/socket/ancdata.c (bsock_sendmsg_internal, bsock_recvmsg_internal): avoid redundant fcntl on Linux [ruby-core:69154] [Feature #11145] * ext/socket/init.c (rsock_s_recvfrom_nonblock): ditto * ext/socket/rubysocket.h (MSG_DONTWAIT_RELIABLE): new macro MSG_DONTWAIT is enough to force non-blocking I/O under Linux, so avoid changing the state of a socket. This will allow certain threads to do a non-destructive non-blocking "peek" while others block (without relying on an extra ppoll syscall). We shall be conservative about enabling this feature since some OSes may have incomplete support for MSG_DONTWAIT. I shall defer to a FreeBSD expert to enable that for FreeBSD. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/socket/rubysocket.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'ext/socket/rubysocket.h') diff --git a/ext/socket/rubysocket.h b/ext/socket/rubysocket.h index 689a7a8219..359d28ea3d 100644 --- a/ext/socket/rubysocket.h +++ b/ext/socket/rubysocket.h @@ -407,9 +407,20 @@ NORETURN(void rsock_sys_fail_raddrinfo_or_sockaddr(const char *, VALUE addr, VAL #if defined(__linux__) static inline int rsock_maybe_fd_writable(int fd) { return 1; } static inline void rsock_maybe_wait_fd(int fd) { } +# ifdef MSG_DONTWAIT +# define MSG_DONTWAIT_RELIABLE 1 +# endif #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 +/* + * some OSes may support MSG_DONTWAIT inconsistently depending on socket + * type, we only expect Linux to support it consistently for all socket types. + */ +#ifndef MSG_DONTWAIT_RELIABLE +# define MSG_DONTWAIT_RELIABLE 0 +#endif + #endif -- cgit v1.2.3