Removed initial Thread for the HTTP_HANDLER, this is not needed here
Removed HTTP_SERVER_SHARED_CONFIGURATION from the library ... not needed by the library. Added HTTP_SERVER_SHARED_CONFIGURATION to the example to show how to share the configuration, if needed
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
note
|
||||
description: "Summary description for {HTTP_SERVER_SHARED_CONFIGURATION}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
HTTP_SERVER_SHARED_CONFIGURATION
|
||||
|
||||
feature -- Access
|
||||
|
||||
server_configuration: detachable HTTP_SERVER_CONFIGURATION
|
||||
-- Shared configuration
|
||||
do
|
||||
if attached server_configuration_cell.item as l_cfg then
|
||||
Result := l_cfg
|
||||
end
|
||||
end
|
||||
|
||||
document_root: STRING_8
|
||||
-- Shared document root
|
||||
do
|
||||
if attached server_configuration as l_cfg then
|
||||
Result := l_cfg.document_root
|
||||
else
|
||||
Result := ""
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_server_configuration (a_cfg: like server_configuration)
|
||||
-- Set `server_configuration' to `a_cfg'.
|
||||
do
|
||||
server_configuration_cell.replace (a_cfg)
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
server_configuration_cell: CELL [detachable HTTP_SERVER_CONFIGURATION]
|
||||
once ("PROCESS")
|
||||
create Result.put (Void)
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2011, Javier Velilla and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
end
|
||||
@@ -8,7 +8,7 @@ deferred class
|
||||
HTTP_HANDLER
|
||||
|
||||
inherit
|
||||
THREAD
|
||||
ANY
|
||||
|
||||
HTTP_CONSTANTS
|
||||
|
||||
@@ -27,6 +27,13 @@ feature {NONE} -- Initialization
|
||||
main_server_set: a_main_server ~ main_server
|
||||
end
|
||||
|
||||
feature -- Output
|
||||
|
||||
log (a_message: READABLE_STRING_8)
|
||||
do
|
||||
io.put_string (a_message)
|
||||
end
|
||||
|
||||
feature -- Inherited Features
|
||||
|
||||
execute
|
||||
@@ -43,14 +50,14 @@ feature -- Inherited Features
|
||||
create l_http_socket.make_server_by_port (l_http_port)
|
||||
if not l_http_socket.is_bound then
|
||||
if is_verbose then
|
||||
print ("Socket could not be bound on port " + l_http_port.out )
|
||||
log ("Socket could not be bound on port " + l_http_port.out )
|
||||
end
|
||||
else
|
||||
l_http_port := l_http_socket.port
|
||||
from
|
||||
l_http_socket.listen (main_server_configuration.max_tcp_clients)
|
||||
if is_verbose then
|
||||
print ("%NHTTP Connection Server ready on port " + l_http_port.out +" : http://localhost:" + l_http_port.out + "/%N")
|
||||
log ("%NHTTP Connection Server ready on port " + l_http_port.out +" : http://localhost:" + l_http_port.out + "/%N")
|
||||
end
|
||||
on_launched (l_http_port)
|
||||
until
|
||||
@@ -59,13 +66,7 @@ feature -- Inherited Features
|
||||
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
|
||||
socket_closed: l_thread_http_socket.is_closed
|
||||
end
|
||||
process_connection (l_thread_http_socket)
|
||||
end
|
||||
end
|
||||
is_stop_requested := main_server.stop_requested
|
||||
@@ -79,10 +80,10 @@ feature -- Inherited Features
|
||||
on_stopped
|
||||
end
|
||||
if is_verbose then
|
||||
print ("HTTP Connection Server ends.")
|
||||
log ("HTTP Connection Server ends.")
|
||||
end
|
||||
rescue
|
||||
print ("HTTP Connection Server shutdown due to exception. Please relaunch manually.")
|
||||
log ("HTTP Connection Server shutdown due to exception. Please relaunch manually.")
|
||||
|
||||
if attached l_http_socket as ll_http_socket then
|
||||
ll_http_socket.cleanup
|
||||
@@ -97,6 +98,18 @@ feature -- Inherited Features
|
||||
retry
|
||||
end
|
||||
|
||||
process_connection (a_socket: TCP_STREAM_SOCKET)
|
||||
-- Process incoming connection
|
||||
do
|
||||
log ("Incoming connection...%N")
|
||||
--| FIXME jfiat [2011/11/03] : should use a Pool of Threads/Handler to process this connection
|
||||
--| also handle permanent connection...?
|
||||
receive_message_and_send_reply (a_socket)
|
||||
a_socket.cleanup
|
||||
ensure
|
||||
socket_closed: a_socket.is_closed
|
||||
end
|
||||
|
||||
feature -- Event
|
||||
|
||||
on_launched (a_port: INTEGER)
|
||||
@@ -121,7 +134,7 @@ feature -- Event
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
|
||||
is_verbose: BOOLEAN
|
||||
-- Is verbose for output messages.
|
||||
do
|
||||
|
||||
@@ -7,9 +7,6 @@ note
|
||||
class
|
||||
HTTP_SERVER
|
||||
|
||||
inherit
|
||||
HTTP_SERVER_SHARED_CONFIGURATION
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
@@ -18,7 +15,6 @@ feature -- Initialization
|
||||
make (cfg: like configuration)
|
||||
do
|
||||
configuration := cfg
|
||||
set_server_configuration (configuration)
|
||||
end
|
||||
|
||||
setup (a_http_handler: HTTP_HANDLER)
|
||||
@@ -30,12 +26,7 @@ feature -- Initialization
|
||||
print ("Starting Web Application Server (port="+ configuration.http_server_port.out +"):%N")
|
||||
end
|
||||
stop_requested := False
|
||||
if configuration.force_single_threaded then
|
||||
a_http_handler.execute
|
||||
else
|
||||
a_http_handler.launch
|
||||
a_http_handler.join
|
||||
end
|
||||
a_http_handler.execute
|
||||
end
|
||||
|
||||
shutdown_server
|
||||
|
||||
Reference in New Issue
Block a user