Class: EventMachine::EvmaTCPServer
- Inherits:
-
Selectable
- Object
- Selectable
- EventMachine::EvmaTCPServer
- Defined in:
- lib/em/pure_ruby.rb
Instance Attribute Summary
Attributes inherited from Selectable
Class Method Summary collapse
-
.start_server(host, port) ⇒ Object
Versions of ruby 1.8.4 later than May 26 2006 will work properly with an object of type TCPServer.
Instance Method Summary collapse
-
#eventable_read ⇒ Object
– accept_nonblock returns an array consisting of the accepted socket and a sockaddr_in which names the peer.
-
#initialize(io) ⇒ EvmaTCPServer
constructor
A new instance of EvmaTCPServer.
-
#schedule_close ⇒ Object
–.
- #select_for_reading? ⇒ Boolean
Methods inherited from Selectable
#close_scheduled?, #get_peername, #get_sockname, #heartbeat, #select_for_writing?, #set_inactivity_timeout
Constructor Details
#initialize(io) ⇒ EvmaTCPServer
Returns a new instance of EvmaTCPServer.
1078 1079 1080 |
# File 'lib/em/pure_ruby.rb', line 1078 def initialize io super io end |
Class Method Details
.start_server(host, port) ⇒ Object
Versions of ruby 1.8.4 later than May 26 2006 will work properly with an object of type TCPServer. Prior versions won’t so we play it safe and just build a socket.
1069 1070 1071 1072 1073 1074 1075 |
# File 'lib/em/pure_ruby.rb', line 1069 def start_server host, port sd = Socket.new( Socket::AF_INET, Socket::SOCK_STREAM, 0 ) sd.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true ) sd.bind( Socket.pack_sockaddr_in( port, host )) sd.listen( 50 ) # 5 is what you see in all the books. Ain't enough. EvmaTCPServer.new sd end |
Instance Method Details
#eventable_read ⇒ Object
– accept_nonblock returns an array consisting of the accepted socket and a sockaddr_in which names the peer. Don’t accept more than 10 at a time.
1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 |
# File 'lib/em/pure_ruby.rb', line 1091 def eventable_read begin 10.times { descriptor,peername = io.accept_nonblock sd = EvmaTCPClient.new descriptor sd.is_server = true EventMachine::event_callback uuid, ConnectionAccepted, sd.uuid } rescue Errno::EWOULDBLOCK, Errno::EAGAIN end end |
#schedule_close ⇒ Object
–
1105 1106 1107 |
# File 'lib/em/pure_ruby.rb', line 1105 def schedule_close @close_scheduled = true end |
#select_for_reading? ⇒ Boolean
1083 1084 1085 |
# File 'lib/em/pure_ruby.rb', line 1083 def select_for_reading? true end |