0
# The uterly famous Thin HTTP server.
0
- # It listen for incoming request through a given
connector0
+ # It listen for incoming request through a given
backend0
# and forward all request to +app+.
0
# Thin::Server.start('/tmp/thin.sock', nil, app)
0
- # == Using a custom
connector0
+ # == Using a custom
backend0
# You can implement your own way to connect the server to its client by creating your
0
- # own
Thin::Connectors::Connector class and pass it as the first argument.
0
+ # own
Backend class and pass it as the first argument.
0
- # connector = Thin::Connectors::MyFancyConnector.new('galaxy://faraway:1345')
0
- # Thin::Server.start(connector, nil, app)
0
+ # backend = Thin::Backends::MyFancyBackend.new('galaxy://faraway:1345')
0
+ # Thin::Server.start(backend, nil, app)
0
# == Rack application (+app+)
0
# All requests will be processed through +app+ that must be a valid Rack adapter.
0
# Application (Rack adapter) called with the request that produces the response.
0
- # Connector handling the connections to the clients.
0
- attr_accessor :connector
0
+ # Backend handling the connections to the clients.
0
+ attr_accessor :backend
0
# Maximum number of file or socket descriptors that the server may open.
0
attr_accessor :maximum_connections
0
# Maximum number of seconds for incoming data to arrive before the connection
0
- def_delegators :@
connector, :timeout, :timeout=
0
+ def_delegators :@
backend, :timeout, :timeout=
0
# Maximum number of connection that can be persistent at the same time.
0
# Most browser never close the connection so most of the time they are closed
0
# when the timeout occur. If we don't control the number of persistent connection,
0
# if would be very easy to overflow the server for a DoS attack.
0
- def_delegators :@
connector, :maximum_persistent_connections, :maximum_persistent_connections=
0
+ def_delegators :@
backend, :maximum_persistent_connections, :maximum_persistent_connections=
0
# Address and port on which the server is listening for connections.
0
- def_delegators :@
connector, :host, :port
0
+ def_delegators :@
backend, :host, :port
0
# UNIX domain socket on which the server is listening for connections.
0
- def_delegator :@
connector, :socket
0
+ def_delegator :@
backend, :socket
0
- def initialize(host_or_socket_or_connector, port=DEFAULT_PORT, app=nil, &block)
0
- # Try to intelligently select which connector to use.
0
- when host_or_socket_or_connector.is_a?(Connectors::Connector)
0
- host_or_socket_or_connector
0
- when host_or_socket_or_connector.include?('/')
0
- Connectors::UnixServer.new(host_or_socket_or_connector)
0
+ def initialize(host_or_socket_or_backend, port=DEFAULT_PORT, app=nil, &block)
0
+ # Try to intelligently select which backend to use.
0
+ when host_or_socket_or_backend.is_a?(Backends::Base)
0
+ host_or_socket_or_backend
0
+ when host_or_socket_or_backend.include?('/')
0
+ Backends::UnixServer.new(host_or_socket_or_backend)
0
-
Connectors::TcpServer.new(host_or_socket_or_connector, port.to_i)
0
+
Backends::TcpServer.new(host_or_socket_or_backend, port.to_i)
0
- @connector.server = self
0
+ @backend.server = self
0
- @maximum_connections = DEFAULT_MAXIMUM_CONNECTIONS
0
- @connector.maximum_persistent_connections = DEFAULT_MAXIMUM_PERSISTENT_CONNECTIONS
0
- @connector.timeout = DEFAULT_TIMEOUT
0
+ @maximum_connections = DEFAULT_MAXIMUM_CONNECTIONS
0
+ @backend.maximum_persistent_connections = DEFAULT_MAXIMUM_PERSISTENT_CONNECTIONS
0
+ @backend.timeout = DEFAULT_TIMEOUT
0
# Allow using Rack builder as a block
0
@app = Rack::Builder.new(&block).to_app if block
0
raise ArgumentError, 'app required' unless @app
0
# See http://rubyeventmachine.com/pub/rdoc/files/EPOLL.html
0
log ">> Thin web server (v#{VERSION::STRING} codename #{VERSION::CODENAME})"
0
debug ">> Debugging ON"
0
- log ">> Listening on #{@connector}, CTRL+C to stop"
0
+ log ">> Listening on #{@backend}, CTRL+C to stop"
0
- EventMachine.run { @
connector.connect }
0
+ EventMachine.run { @
backend.connect }
0
# Do not accept anymore connection
0
unless wait_for_connections_and_stop
0
# Still some connections running, schedule a check later
0
- @
connector.close_connections
0
+ @
backend.close_connections
0
- "thin server (#{@
connector})"
0
+ "thin server (#{@
backend})"