lib/ionian/server.rb in ionian-0.6.1 vs lib/ionian/server.rb in ionian-0.6.2

- old
+ new

@@ -8,10 +8,11 @@ # A convenient wrapper for TCP and Unix server sockets (UDP doesn't use # a server). # # Accepts an optional block that is passed to #register_accept_listener. + # Server opens listening socket on instantiation if this block is provided. # # Args: # interface: The address of the network interface to bind to. # Defaults to all. # protocol: :tcp, :unix. Default is :tcp. @@ -39,10 +40,12 @@ when :udp raise ArgumentError, "UDP should be implemented with Ionian::Socket." when :unix @server = UNIXServer.new @interface end + + listen if block_given? end # Starts the socket server listening for connections. # Blocks registered with #register_accept_listener will # be run when a connection is accepted. @@ -70,9 +73,14 @@ # Shutdown the server socket and stop listening for connections. def close @server.close if @server @accept_thread.join if @accept_thread @accept_thread = nil + end + + # Returns true if the server listener socket is closed. + def closed? + @server.closed? end # Register a block to be run when server accepts a client connection. # The connected client is passed to the block as an Ionain::Client. def register_accept_listener &block \ No newline at end of file