diff net/http/server/server.rb @ 0:1eef88068f9f tip

initial commit of maze game source
author ferencd
date Sun, 15 Sep 2019 11:46:47 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/net/http/server/server.rb	Sun Sep 15 11:46:47 2019 +0200
@@ -0,0 +1,49 @@
+require 'net/http/server/daemon'
+
+require 'net/protocol'
+
+module Net
+  class HTTP < Protocol
+    module Server
+      #
+      # Starts the HTTP Server.
+      #
+      # @param [Hash] options
+      #   Options for the server.
+      #
+      # @option options [String] :host (DEFAULT_HOST)
+      #   The host to run on.
+      #
+      # @option options [String] :port (DEFAULT_PORT)
+      #   The port to listen on.
+      #
+      # @option options [Integer] :max_connections (MAX_CONNECTIONS)
+      #   The maximum number of simultaneous connections.
+      #
+      # @option options [Boolean] :background (false)
+      #   Specifies whether to run the server in the background or
+      #   foreground.
+      #
+      # @option options [#call] :handler
+      #   The HTTP Request Handler object.
+      #
+      # @yield [request, socket]
+      #   If a block is given, it will be used to process HTTP Requests.
+      #
+      # @yieldparam [Hash{Symbol => String,Array,Hash}] request
+      #   The HTTP Request.
+      #
+      # @yieldparam [TCPSocket] socket
+      #   The TCP socket of the client.
+      #
+      def Server.run(options={},&block)
+        daemon = Daemon.new(options,&block)
+
+        daemon.start
+        daemon.join unless options[:background]
+        return daemon
+      end
+
+    end
+  end
+end