lib/reel/server.rb in reel-0.3.0 vs lib/reel/server.rb in reel-0.4.0.pre
- old
+ new
@@ -1,21 +1,26 @@
module Reel
class Server
include Celluloid::IO
+ # How many connections to backlog in the TCP accept queue
+ DEFAULT_BACKLOG = 100
+
# FIXME: remove respond_to? check after Celluloid 1.0
finalizer :finalize if respond_to?(:finalizer)
- def initialize(host, port, &callback)
+ def initialize(host, port, backlog = DEFAULT_BACKLOG, &callback)
# This is actually an evented Celluloid::IO::TCPServer
@server = TCPServer.new(host, port)
- @server.listen(1024)
+ @server.listen(backlog)
@callback = callback
async.run
end
+ execute_block_on_receiver :initialize
+
def finalize
- @server.close
+ @server.close if @server
end
def run
loop { async.handle_connection @server.accept }
end