diff options
author | Eric Wong <e+absinthe@yhbt.net> | 2010-09-25 01:36:13 -0700 |
---|---|---|
committer | Eric Wong <e@yhbt.net> | 2010-09-25 08:32:43 +0000 |
commit | db53263856d864ba6273e6cac73011f699509d71 (patch) | |
tree | 033ae7617bc9d0c4d82ba366b7731a9dba746b49 | |
parent | a82dc40c2a509c4ab692da34b572693f243fbfae (diff) | |
download | kgio-db53263856d864ba6273e6cac73011f699509d71.tar.gz |
MSG_DONTWAIT is less consistently implemented/supported on other platforms on stream sockets, so fallback to fcntl() + read()/write() for stream sockets. This also fixes our previously broken support of non-MSG_DONTWAIT systems.
-rw-r--r-- | ext/kgio/kgio_ext.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/ext/kgio/kgio_ext.c b/ext/kgio/kgio_ext.c index 45c8041..6dbccbc 100644 --- a/ext/kgio/kgio_ext.c +++ b/ext/kgio/kgio_ext.c @@ -60,8 +60,19 @@ accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) return fd; } #endif /* !HAVE_ACCEPT4 */ - +#if defined(__linux__) static int accept4_flags = SOCK_CLOEXEC; + +/* + * we know MSG_DONTWAIT works properly on all stream sockets under Linux + * we can define this macro for other platforms as people care and + * notice. + */ +# define USE_MSG_DONTWAIT +#else +static int accept4_flags = SOCK_CLOEXEC | SOCK_NONBLOCK; +#endif + static VALUE cSocket; static VALUE localhost; static VALUE mKgio_WaitReadable, mKgio_WaitWritable; @@ -236,7 +247,7 @@ static int read_check(struct io_args *a, long n, const char *msg) return 0; } -#ifdef MSG_DONTWAIT +#ifdef USE_MSG_DONTWAIT /* * Document-method: Kgio::SocketMethods#kgio_read @@ -263,9 +274,9 @@ retry: goto retry; return a.buf; } -#else /* ! MSG_DONTWAIT */ -# define kgio_recv kgio_write -#endif /* MSG_DONTWAIT */ +#else /* ! USE_MSG_DONTWAIT */ +# define kgio_recv kgio_read +#endif /* USE_MSG_DONTWAIT */ /* * Document-method: Kgio::PipeMethods#kgio_read @@ -347,7 +358,7 @@ retry: return a.buf; } -#ifdef MSG_DONTWAIT +#ifdef USE_MSG_DONTWAIT /* * This method behaves like Kgio::PipeMethods#kgio_write, except * it will use send(2) with the MSG_DONTWAIT flag on sockets to @@ -365,9 +376,9 @@ retry: goto retry; return a.buf; } -#else /* ! MSG_DONTWAIT */ +#else /* ! USE_MSG_DONTWAIT */ # define kgio_send kgio_write -#endif /* ! MSG_DONTWAIT */ +#endif /* ! USE_MSG_DONTWAIT */ /* * call-seq: |