module PacketThief::Handlers::SSLServer::InitialServer
Handles the initial listening socket. We can't seem to use EM.start_server -> EM.detach -> em.watch without triggering (in EventMachine 1.0.0):
Assertion failed: (sd != INVALID_SOCKET), function _RunSelectOnce, file em.cpp, line 893.
So we handle the server muckery ourselves.
Public Class Methods
new(servsocket, ssl_class, args, block)
click to toggle source
# File lib/packetthief/handlers/ssl_server.rb, line 95 def initialize(servsocket, ssl_class, args, block) @servsocket = servsocket @ssl_class = ssl_class @args = args @block = block end
Public Instance Methods
notify_readable()
click to toggle source
# File lib/packetthief/handlers/ssl_server.rb, line 102 def notify_readable logdebug "(#{@ssl_class}): Received a new connection, spawning a #{@ssl_class}" sock = @servsocket.accept_nonblock ::EM.watch sock, @ssl_class, sock, *@args do |h| logdebug "after initialize" h.server_handler = self h.notify_readable = true # Now call the caller's block. @block.call(h) if @block # And finally finish initialization by applying the context to an # SSLSocket, and setting the internal state. h.tls_begin unless h.tcpsocket.closed? end end
notify_writable()
click to toggle source
# File lib/packetthief/handlers/ssl_server.rb, line 119 def notify_writable logdebug "(#{@ssl_class}): Server socket notify writable" end
stop_server()
click to toggle source
This must be called explicitly. EM doesn't seem to have a callback for when the EM::run call ends.
# File lib/packetthief/handlers/ssl_server.rb, line 124 def stop_server unless @servsocket.closed? detach @servsocket.close end end
unbind()
click to toggle source
# File lib/packetthief/handlers/ssl_server.rb, line 131 def unbind logdebug "(#{@ssl_class}): Stopping server socket" end