accept_nonblock() public

Accepts an incoming connection using accept(2) after O_NONBLOCK is set for the underlying file descriptor. It returns an accepted TCPSocket for the incoming connection.

Example

     require 'socket'
     serv = TCPServer.new(2202)
     begin
       sock = serv.accept_nonblock
     rescue Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR
       IO.select([serv])
       retry
     end
     # sock is an accepted socket.

Refer to Socket#accept for the exceptions that may be thrown if the call to TCPServer#accept_nonblock fails.

TCPServer#accept_nonblock may raise any error corresponding to accept(2) failure, including Errno::EAGAIN.

See

Show source
Register or log in to add new notes.