Class: EventMachine::EvmaUNIXServer

Inherits:
Selectable show all
Defined in:
lib/em/pure_ruby.rb

Instance Attribute Summary

Attributes inherited from Selectable

#io, #is_server, #uuid

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Selectable

#close_scheduled?, #get_peername, #get_sockname, #heartbeat, #select_for_writing?, #set_inactivity_timeout

Constructor Details

#initialize(io) ⇒ EvmaUNIXServer



1112
1113
1114
# File 'lib/em/pure_ruby.rb', line 1112

def initialize io
  super io
end

Class Method Details

.start_server(chain) ⇒ 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.



1103
1104
1105
1106
1107
1108
1109
# File 'lib/em/pure_ruby.rb', line 1103

def start_server chain
  sd = Socket.new( Socket::AF_LOCAL, Socket::SOCK_STREAM, 0 )
  sd.setsockopt( Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true )
  sd.bind( Socket.pack_sockaddr_un( chain ))
  sd.listen( 50 ) # 5 is what you see in all the books. Ain't enough.
  EvmaUNIXServer.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.



1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
# File 'lib/em/pure_ruby.rb', line 1125

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

#schedule_closeObject



1138
1139
1140
# File 'lib/em/pure_ruby.rb', line 1138

def schedule_close
  @close_scheduled = true
end

#select_for_reading?Boolean



1117
1118
1119
# File 'lib/em/pure_ruby.rb', line 1117

def select_for_reading?
  true
end