diff --git a/library/configuration/http_server_configuration.e b/library/configuration/http_server_configuration.e index a407f8db..5b552e35 100644 --- a/library/configuration/http_server_configuration.e +++ b/library/configuration/http_server_configuration.e @@ -23,7 +23,7 @@ feature {NONE} -- Initialization feature -- Access - Server_details : STRING = "Server : NANO Eiffel Server" + Server_details : STRING = "Server : NINO Eiffel Server" document_root: STRING assign set_document_root http_server_port: INTEGER assign set_http_server_port @@ -32,6 +32,9 @@ feature -- Access socket_connect_timeout: INTEGER assign set_socket_connect_timeout force_single_threaded: BOOLEAN assign set_force_single_threaded + is_verbose: BOOLEAN assign set_is_verbose + -- Display verbose message to the output? + feature -- Element change set_http_server_port (v: like http_server_port) @@ -64,6 +67,11 @@ feature -- Element change force_single_threaded := v end + set_is_verbose (b: BOOLEAN) + -- Set `is_verbose' to `b' + do + is_verbose := b + end note copyright: "2011-2011, Javier Velilla and others" diff --git a/library/http_handler.e b/library/http_handler.e index 0489ad19..bfc9cb1c 100644 --- a/library/http_handler.e +++ b/library/http_handler.e @@ -38,21 +38,32 @@ feature -- Inherited Features l_http_socket: detachable TCP_STREAM_SOCKET l_http_port: INTEGER do + launched := False + port := 0 is_stop_requested := False l_http_port := main_server_configuration.http_server_port create l_http_socket.make_server_by_port (l_http_port) if not l_http_socket.is_bound then - print ("Socket could not be bound on port " + l_http_port.out ) + if is_verbose then + print ("Socket could not be bound on port " + l_http_port.out ) + end else + l_http_port := l_http_socket.port + port := l_http_port from l_http_socket.listen (main_server_configuration.max_tcp_clients) - print ("%NHTTP Connection Server ready on port " + l_http_port.out +"%N") + if is_verbose then + print ("%NHTTP Connection Server ready on port " + l_http_port.out +" : http://localhost:" + l_http_port.out + "/%N") + end + launched := True until is_stop_requested loop l_http_socket.accept if not is_stop_requested then if attached l_http_socket.accepted as l_thread_http_socket then + --| FIXME jfiat [2011/11/03] : should launch a new thread to handle this connection + --| also handle permanent connection...? receive_message_and_send_reply (l_thread_http_socket) l_thread_http_socket.cleanup check @@ -67,7 +78,10 @@ feature -- Inherited Features socket_is_closed: l_http_socket.is_closed end end - print ("HTTP Connection Server ends.") + launched := False + if is_verbose then + print ("HTTP Connection Server ends.") + end rescue print ("HTTP Connection Server shutdown due to exception. Please relaunch manually.") @@ -77,15 +91,29 @@ feature -- Inherited Features socket_is_closed: ll_http_socket.is_closed end end + launched := False is_stop_requested := True retry end feature -- Access + + is_verbose: BOOLEAN + -- Is verbose for output messages. + do + Result := main_server_configuration.is_verbose + end is_stop_requested: BOOLEAN -- Set true to stop accept loop + launched: BOOLEAN + -- Server launched and listening on `port' + + port: INTEGER + -- Listening port. + --| 0: not launched + feature {NONE} -- Access main_server: HTTP_SERVER @@ -97,9 +125,6 @@ feature {NONE} -- Access Result := main_server.configuration end - Max_fragments: INTEGER = 1000 - -- Defines the maximum number of fragments that can be received - feature -- Status setting shutdown @@ -114,7 +139,7 @@ feature -- Execution require socket_attached: client_socket /= Void -- socket_valid: client_socket.is_open_read and then client_socket.is_open_write - a_http_socket:client_socket /= Void and then not client_socket.is_closed + a_http_socket: not client_socket.is_closed deferred end diff --git a/library/http_server.e b/library/http_server.e index e4e02d64..a21e048c 100644 --- a/library/http_server.e +++ b/library/http_server.e @@ -21,7 +21,7 @@ feature -- Initialization set_server_configuration (configuration) end - setup (a_http_handler : HTTP_HANDLER) + setup (a_http_handler: HTTP_HANDLER) require a_http_handler_valid: a_http_handler /= Void do