Class: ServerSide::HTTP::Connection
- Defined in:
- lib/serverside/connection.rb
Overview
The Connection class represents HTTP connections. Each connection instance creates a separate thread for execution and processes incoming requests in a loop until the connection is closed by either server or client, thus implementing HTTP 1.1 persistent connections.
Instance Method Summary collapse
-
#initialize(socket, request_class) ⇒ Connection
constructor
Initializes the request instance.
-
#process ⇒ Object
Processes incoming requests by parsing them and then responding.
Constructor Details
#initialize(socket, request_class) ⇒ Connection
Initializes the request instance. A new thread is created for processing requests.
13 14 15 16 |
# File 'lib/serverside/connection.rb', line 13 def initialize(socket, request_class) @socket, @request_class = socket, request_class @thread = Thread.new {process} end |
Instance Method Details
#process ⇒ Object
Processes incoming requests by parsing them and then responding. If any error occurs, or the connection is not persistent, the connection is closed.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/serverside/connection.rb', line 21 def process while true # the process function is expected to return true or a non-nil value # if the connection is to persist. break unless @request_class.new(@socket).process end rescue => e # We don't care. Just close the connection. ensure @socket.close end |