0
- DEFAULT_TIMEOUT = 30 #sec
0
+ DEFAULT_TIMEOUT = 30 #sec
0
+ DEFAULT_MAXIMUM_CONNECTIONS = 1024
0
+ DEFAULT_MAXIMUM_PERSISTENT_CONNECTIONS = 512
0
# Application (Rack adapter) called with the request that produces the response.
0
attr_accessor :connector
0
# Maximum number of file or socket descriptors that the server may open.
0
- attr_
reader :descriptor_table_size0
+ attr_
accessor :maximum_connections0
# Maximum number of seconds for incoming data to arrive before the connection
0
def_delegators :@connector, :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
# Address and port on which the server is listening for connections.
0
def_delegators :@connector, :host, :port
0
Connectors::TcpServer.new(host_or_socket_or_connector, port.to_i)
0
- @connector.server = self
0
+ @connector.server = self
0
+ @maximum_connections = DEFAULT_MAXIMUM_CONNECTIONS
0
+ @connector.maximum_persistent_connections = DEFAULT_MAXIMUM_PERSISTENT_CONNECTIONS
0
+ @connector.timeout = DEFAULT_TIMEOUT
0
# Allow using Rack builder as a block
0
@app = Rack::Builder.new(&block).to_app if block
0
def self.start(*args, &block)
0
new(*args, &block).start!
0
- # Set the maximum number of socket descriptors that the server may open.
0
- # The process needs to have required privilege to set it higher the 1024 on
0
- def descriptor_table_size=(size)
0
- @descriptor_table_size = EventMachine.set_descriptor_table_size(size)
0
- log ">> Setting descriptor table size to #{@descriptor_table_size}"
0
- if @descriptor_table_size < size
0
- log "!! descriptor table size smaller then requested, " +
0
- "run with sudo to set higher"
0
- @descriptor_table_size
0
# Start the server and listen for connections.
0
# Also register signals:
0
# * INT calls +stop+ to shutdown gracefully.
0
log ">> Thin web server (v#{VERSION::STRING} codename #{VERSION::CODENAME})"
0
debug ">> Debugging ON"
0
+ set_descriptor_table_size
0
log ">> Listening on #{@connector}, CTRL+C to stop"
0
+ # Set the maximum number of socket descriptors that the server may open.
0
+ # The process needs to have required privilege to set it higher the 1024 on
0
+ def set_descriptor_table_size
0
+ requested_maximum_connections = @maximum_connections
0
+ @maximum_connections = EventMachine.set_descriptor_table_size(requested_maximum_connections)
0
+ log ">> Setting maximum connections to #{@maximum_connections}"
0
+ if @maximum_connections < requested_maximum_connections
0
+ log "!! Maximum connections smaller then requested, " +
0
+ "run with sudo to set higher"
Comments
No one has commented yet.