diff options
Diffstat (limited to 'ext/socket')
-rw-r--r-- | ext/socket/socket.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c index 514ba3fd59..c141e6be33 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -1454,6 +1454,24 @@ tcp_svr_init(int argc, VALUE *argv, VALUE 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, rb_io_t *fptr, struct sockaddr *sockaddr, socklen_t *len) { @@ -1465,6 +1483,7 @@ s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, socklen if (fd2 < 0) { rb_sys_fail("accept(2)"); } + make_fd_nonblock(fd2); return init_sock(rb_obj_alloc(klass), fd2); } |