Class: Plum::Rack::TCPListener

Inherits:
BaseListener show all
Defined in:
lib/plum/rack/listener.rb

Instance Method Summary collapse

Methods inherited from BaseListener

#method_missing, #stop

Constructor Details

#initialize(lc) ⇒ TCPListener

Returns a new instance of TCPListener.



23
24
25
# File 'lib/plum/rack/listener.rb', line 23

def initialize(lc)
  @server = ::TCPServer.new(lc[:hostname], lc[:port])
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Plum::Rack::BaseListener

Instance Method Details

#accept(svc) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/plum/rack/listener.rb', line 31

def accept(svc)
  sock = @server.accept
  Thread.start {
    begin
      plum = ::Plum::HTTPServerConnection.new(sock.method(:write))
      sess = Session.new(svc, sock, plum)
      sess.run
    rescue ::Plum::LegacyHTTPError => e
      svc.logger.info "legacy HTTP client: #{e}"
      sess = LegacySession.new(svc, e, sock)
      sess.run
    rescue Errno::ECONNRESET, EOFError # closed
    rescue => e
      svc.log_exception(e)
    ensure
      sock.close
    end
  }
end

#to_ioObject



27
28
29
# File 'lib/plum/rack/listener.rb', line 27

def to_io
  @server.to_io
end