[MacRuby] #1195: Socket#accept_nonblock blocks for Unix domain socket
#1195: Socket#accept_nonblock blocks for Unix domain socket --------------------------------------+------------------------------------- Reporter: warpflyght@… | Owner: lsansonetti@… Type: defect | Status: new Priority: major | Milestone: Component: MacRuby | Keywords: --------------------------------------+------------------------------------- Socket#accept_nonblock (and UNIXServer#accept_nonblock) appear to block. I haven't tried constructing a UDP or TCP socket with Socket, but I suspect this issue affects all Socket subclasses. Test programs: UNIXServer: {{{ #!ruby require 'socket' require 'fileutils' FileUtils.rm_f("/tmp/sock") serv = UNIXServer.new("/tmp/sock") begin warn "Accepting." sock = serv.accept_nonblock rescue Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR warn "Would block; retrying." retry end warn "Have socket." }}} Socket: {{{ #!ruby require 'socket' require 'fileutils' FileUtils.rm_f("/tmp/sock") serv = Socket.new(Socket::AF_UNIX, Socket::SOCK_STREAM, 0) serv.bind(Socket.sockaddr_un("/tmp/sock")) serv.listen(1) begin warn "Accepting." sock, sockaddr = serv.accept_nonblock rescue Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR warn "Would block; retrying." retry end warn "Have socket." }}} When run with Ruby 1.8.7 on my Snow Leopard machine, these print "Accepting" followed by "Would block; retrying" repeatedly, as expected. Under MacRuby r5278 on the same system, both programs just print "Accepting" and do nothing. Connecting to the socket immediately prints "Have socket" under both interpreters. I searched Trac for duplicates, but the closest I found was #554. In the case of IO#read_nonblock and IO#write_nonblock, the C functions are actually unimplemented; in this case, they are implemented, but don't work as documented. -- Ticket URL: <http://www.macruby.org/trac/ticket/1195> MacRuby <http://macruby.org/>
#1195: Socket#accept_nonblock blocks for Unix domain socket --------------------------------------+------------------------------------- Reporter: warpflyght@… | Owner: lsansonetti@… Type: defect | Status: new Priority: major | Milestone: Component: MacRuby | Keywords: --------------------------------------+------------------------------------- Comment(by warpflyght@…): Looks like this is because of this declaration near the top of socket.c: {{{ #!c // TODO #define rb_io_set_nonblock(x) }}} I ported the Ruby 1.9.2 implementation from io.c, and it has worked in my testing thus far: {{{ #!c void rb_io_set_nonblock(rb_io_t *fptr) { int oflags; #ifdef F_GETFL oflags = fcntl(fptr->fd, F_GETFL); if (oflags == -1) { rb_sys_fail(StringValueCStr(fptr->path)); } #else oflags = 0; #endif if ((oflags & O_NONBLOCK) == 0) { oflags |= O_NONBLOCK; if (fcntl(fptr->fd, F_SETFL, oflags) == -1) { rb_sys_fail(StringValueCStr(fptr->path)); } } } }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/1195#comment:1> MacRuby <http://macruby.org/>
#1195: Socket#accept_nonblock blocks for Unix domain socket --------------------------------------+------------------------------------- Reporter: warpflyght@… | Owner: lsansonetti@… Type: defect | Status: new Priority: major | Milestone: Component: MacRuby | Keywords: --------------------------------------+------------------------------------- Comment(by warpflyght@…): I've submitted a GitHub pull request with the fix: [https://github.com/MacRuby/MacRuby/pull/13]. -- Ticket URL: <http://www.macruby.org/trac/ticket/1195#comment:2> MacRuby <http://macruby.org/>
#1195: Socket#accept_nonblock blocks for Unix domain socket --------------------------------------+------------------------------------- Reporter: warpflyght@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: major | Milestone: MacRuby 0.11 Component: MacRuby | Resolution: fixed Keywords: | --------------------------------------+------------------------------------- Changes (by watson1978@…): * status: new => closed * resolution: => fixed * milestone: => MacRuby 0.11 Comment: Fixed with https://github.com/MacRuby/MacRuby/commit/4aaea9412dbf51da5d8abb41f00a459bdf... -- Ticket URL: <http://www.macruby.org/trac/ticket/1195#comment:3> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby