Class: EventMachine::EvmaTCPServer

Inherits:
Selectable show all
Defined in:
lib/pr_eventmachine.rb

Instance Attribute Summary

Attributes inherited from Selectable

#io, #uuid

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Selectable

#close_scheduled?, #get_peername, #select_for_writing?

Constructor Details

#initialize(io) ⇒ EvmaTCPServer

Returns a new instance of EvmaTCPServer.



543
544
545
# File 'lib/pr_eventmachine.rb', line 543

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.



534
535
536
537
538
539
540
# File 'lib/pr_eventmachine.rb', line 534

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_readObject

– 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.



556
557
558
559
560
561
562
563
564
565
# File 'lib/pr_eventmachine.rb', line 556

def eventable_read
  begin
    10.times {
      descriptor,peername = io.accept_nonblock
      sd = StreamObject.new descriptor
      EventMachine::event_callback uuid, ConnectionAccepted, sd.uuid
    }
  rescue Errno::EWOULDBLOCK, Errno::EAGAIN
  end
end

#select_for_reading?Boolean

Returns:

  • (Boolean)


548
549
550
# File 'lib/pr_eventmachine.rb', line 548

def select_for_reading?
  true
end