ext/kgio/accept.c in kgio-2.5.0 vs ext/kgio/accept.c in kgio-2.6.0

- old
+ new

@@ -202,10 +202,11 @@ switch (errno) { case EAGAIN: if (force_nonblock) return Qnil; a->fd = my_fileno(a->accept_io); + errno = EAGAIN; set_blocking_or_block(a->fd); #ifdef ECONNABORTED case ECONNABORTED: #endif /* ECONNABORTED */ #ifdef EPROTO @@ -280,12 +281,12 @@ * * An optional +flags+ argument may also be specifed to override the * value of +Kgio.accept_cloexec+ and +Kgio.accept_nonblock+. +flags+ * is a bitmask that may contain any combination of: * - * - Fcntl::FD_CLOEXEC - close-on-exec flag - * - IO::NONBLOCK - non-blocking flag + * - Kgio::SOCK_CLOEXEC - close-on-exec flag + * - Kgio::SOCK_NONBLOCK - non-blocking flag */ static VALUE tcp_tryaccept(int argc, VALUE *argv, VALUE self) { struct sockaddr_storage addr; socklen_t addrlen = sizeof(struct sockaddr_storage); @@ -317,12 +318,12 @@ * * An optional +flags+ argument may also be specifed to override the * value of +Kgio.accept_cloexec+ and +Kgio.accept_nonblock+. +flags+ * is a bitmask that may contain any combination of: * - * - Fcntl::FD_CLOEXEC - close-on-exec flag - * - IO::NONBLOCK - non-blocking flag + * - Kgio::SOCK_CLOEXEC - close-on-exec flag + * - Kgio::SOCK_NONBLOCK - non-blocking flag */ static VALUE tcp_accept(int argc, VALUE *argv, VALUE self) { struct sockaddr_storage addr; socklen_t addrlen = sizeof(struct sockaddr_storage); @@ -351,12 +352,12 @@ * * An optional +flags+ argument may also be specifed to override the * value of +Kgio.accept_cloexec+ and +Kgio.accept_nonblock+. +flags+ * is a bitmask that may contain any combination of: * - * - Fcntl::FD_CLOEXEC - close-on-exec flag - * - IO::NONBLOCK - non-blocking flag + * - Kgio::SOCK_CLOEXEC - close-on-exec flag + * - Kgio::SOCK_NONBLOCK - non-blocking flag */ static VALUE unix_tryaccept(int argc, VALUE *argv, VALUE self) { struct accept_args a; @@ -386,12 +387,12 @@ * * An optional +flags+ argument may also be specifed to override the * value of +Kgio.accept_cloexec+ and +Kgio.accept_nonblock+. +flags+ * is a bitmask that may contain any combination of: * - * - Fcntl::FD_CLOEXEC - close-on-exec flag - * - IO::NONBLOCK - non-blocking flag + * - Kgio::SOCK_CLOEXEC - close-on-exec flag + * - Kgio::SOCK_NONBLOCK - non-blocking flag */ static VALUE unix_accept(int argc, VALUE *argv, VALUE self) { struct accept_args a; @@ -492,9 +493,21 @@ void init_kgio_accept(void) { VALUE cUNIXServer, cTCPServer; VALUE mKgio = rb_define_module("Kgio"); + + /* + * this maps to the SOCK_NONBLOCK constant in Linux for setting + * the non-blocking flag on newly accepted sockets. + */ + rb_define_const(mKgio, "SOCK_NONBLOCK", INT2NUM(SOCK_NONBLOCK)); + + /* + * this maps to the SOCK_CLOEXEC constant in Linux for setting + * the close-on-exec flag on newly accepted descriptors. + */ + rb_define_const(mKgio, "SOCK_CLOEXEC", INT2NUM(SOCK_CLOEXEC)); localhost = rb_const_get(mKgio, rb_intern("LOCALHOST")); cKgio_Socket = rb_const_get(mKgio, rb_intern("Socket")); cClientSocket = cKgio_Socket; mSocketMethods = rb_const_get(mKgio, rb_intern("SocketMethods"));