File: //usr/share/ri/3.0.0/system/Socket/accept_nonblock-i.ri
U:RDoc::AnyMethod[iI"accept_nonblock:ETI"Socket#accept_nonblock;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [
I":Accepts an incoming connection using accept(2) after ;TI";O_NONBLOCK is set for the underlying file descriptor. ;TI"8It returns an array containing the accepted socket ;TI"3for the incoming connection, _client_socket_, ;TI"(and an Addrinfo, _client_addrinfo_.;To:RDoc::Markup::BlankLine S:RDoc::Markup::Heading:
leveli: textI"Example;To:RDoc::Markup::Verbatim; [I"'# In one script, start this first
;TI"require 'socket'
;TI"include Socket::Constants
;TI"2socket = Socket.new(AF_INET, SOCK_STREAM, 0)
;TI"6sockaddr = Socket.sockaddr_in(2200, 'localhost')
;TI"socket.bind(sockaddr)
;TI"socket.listen(5)
;TI"%begin # emulate blocking accept
;TI"? client_socket, client_addrinfo = socket.accept_nonblock
;TI"+rescue IO::WaitReadable, Errno::EINTR
;TI" IO.select([socket])
;TI"
retry
;TI" end
;TI"?puts "The client said, '#{client_socket.readline.chomp}'"
;TI"1client_socket.puts "Hello from script one!"
;TI"socket.close
;TI"
;TI",# In another script, start this second
;TI"require 'socket'
;TI"include Socket::Constants
;TI"2socket = Socket.new(AF_INET, SOCK_STREAM, 0)
;TI"6sockaddr = Socket.sockaddr_in(2200, 'localhost')
;TI"socket.connect(sockaddr)
;TI"(socket.puts "Hello from script 2."
;TI"8puts "The server said, '#{socket.readline.chomp}'"
;TI"socket.close
;T:@format0o;
; [I"NRefer to Socket#accept for the exceptions that may be thrown if the call ;TI" to _accept_nonblock_ fails.;T@o;
; [I"TSocket#accept_nonblock may raise any error corresponding to accept(2) failure, ;TI""including Errno::EWOULDBLOCK.;T@o;
; [I"bIf the exception is Errno::EWOULDBLOCK, Errno::EAGAIN, Errno::ECONNABORTED or Errno::EPROTO, ;TI")it is extended by IO::WaitReadable. ;TI"[So IO::WaitReadable can be used to rescue the exceptions for retrying accept_nonblock.;T@o;
; [I"OBy specifying a keyword argument _exception_ to +false+, you can indicate ;TI"Nthat accept_nonblock should not raise an IO::WaitReadable exception, but ;TI"0return the symbol +:wait_readable+ instead.;T@S;;
i;I"See;To:RDoc::Markup::List:
@type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o;
; [I"Socket#accept;T:
@fileI"ext/socket/lib/socket.rb;T:0@omit_headings_from_table_of_contents_below0I"Ksocket.accept_nonblock([options]) => [client_socket, client_addrinfo]
;T0[ I"(exception: true);T@LFI"Socket;TcRDoc::NormalClass00