summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-07 16:44:17 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-07 16:44:17 +0000
commit56f39ded333293a4489cd0eb0b75e3801fd57a9c (patch)
tree162a5ba5134b2879905885255fcfe7a389fe7f0a /ext
parentbcdcde3c64cbb3d0121640013ce8fa6fc8d9692a (diff)
merge revision(s) 13699:
* ext/socket/socket.c (s_accept_nonblock): make accepted fd nonblocking. [ruby-talk:274079] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_6@16899 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/socket/socket.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 4c23a1c..22e178a 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -1464,6 +1464,24 @@ tcp_svr_init(argc, argv, sock)
return init_inetsock(sock, Qnil, arg1, Qnil, Qnil, INET_SERVER);
}
+static void
+make_fd_nonblock(int fd)
+{
+ int flags;
+#ifdef F_GETFL
+ flags = fcntl(fd, F_GETFL);
+ if (flags == -1) {
+ rb_sys_fail(0);
+ }
+#else
+ flags = 0;
+#endif
+ flags |= O_NONBLOCK;
+ if (fcntl(fd, F_SETFL, flags) == -1) {
+ rb_sys_fail(0);
+ }
+}
+
static VALUE
s_accept_nonblock(VALUE klass, OpenFile *fptr, struct sockaddr *sockaddr, socklen_t *len)
{
@@ -1475,6 +1493,7 @@ s_accept_nonblock(VALUE klass, OpenFile *fptr, struct sockaddr *sockaddr, sockle
if (fd2 < 0) {
rb_sys_fail("accept(2)");
}
+ make_fd_nonblock(fd2);
return init_sock(rb_obj_alloc(klass), fd2);
}