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:
@@ -9,6 +9,8 @@ class
|
|||||||
inherit
|
inherit
|
||||||
ARGUMENTS
|
ARGUMENTS
|
||||||
|
|
||||||
|
HTTP_SERVER_SHARED_CONFIGURATION
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
@@ -24,6 +26,7 @@ feature {NONE} -- Initialization
|
|||||||
create l_cfg.make
|
create l_cfg.make
|
||||||
l_cfg.http_server_port := 9_000
|
l_cfg.http_server_port := 9_000
|
||||||
l_cfg.document_root := default_document_root
|
l_cfg.document_root := default_document_root
|
||||||
|
set_server_configuration (l_cfg)
|
||||||
debug ("nino")
|
debug ("nino")
|
||||||
l_cfg.set_is_verbose (True)
|
l_cfg.set_is_verbose (True)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ deferred class
|
|||||||
HTTP_HANDLER
|
HTTP_HANDLER
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
THREAD
|
ANY
|
||||||
|
|
||||||
HTTP_CONSTANTS
|
HTTP_CONSTANTS
|
||||||
|
|
||||||
@@ -27,6 +27,13 @@ feature {NONE} -- Initialization
|
|||||||
main_server_set: a_main_server ~ main_server
|
main_server_set: a_main_server ~ main_server
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Output
|
||||||
|
|
||||||
|
log (a_message: READABLE_STRING_8)
|
||||||
|
do
|
||||||
|
io.put_string (a_message)
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Inherited Features
|
feature -- Inherited Features
|
||||||
|
|
||||||
execute
|
execute
|
||||||
@@ -43,14 +50,14 @@ feature -- Inherited Features
|
|||||||
create l_http_socket.make_server_by_port (l_http_port)
|
create l_http_socket.make_server_by_port (l_http_port)
|
||||||
if not l_http_socket.is_bound then
|
if not l_http_socket.is_bound then
|
||||||
if is_verbose 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
|
end
|
||||||
else
|
else
|
||||||
l_http_port := l_http_socket.port
|
l_http_port := l_http_socket.port
|
||||||
from
|
from
|
||||||
l_http_socket.listen (main_server_configuration.max_tcp_clients)
|
l_http_socket.listen (main_server_configuration.max_tcp_clients)
|
||||||
if is_verbose then
|
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
|
end
|
||||||
on_launched (l_http_port)
|
on_launched (l_http_port)
|
||||||
until
|
until
|
||||||
@@ -59,13 +66,7 @@ feature -- Inherited Features
|
|||||||
l_http_socket.accept
|
l_http_socket.accept
|
||||||
if not is_stop_requested then
|
if not is_stop_requested then
|
||||||
if attached l_http_socket.accepted as l_thread_http_socket 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
|
process_connection (l_thread_http_socket)
|
||||||
--| 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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
is_stop_requested := main_server.stop_requested
|
is_stop_requested := main_server.stop_requested
|
||||||
@@ -79,10 +80,10 @@ feature -- Inherited Features
|
|||||||
on_stopped
|
on_stopped
|
||||||
end
|
end
|
||||||
if is_verbose then
|
if is_verbose then
|
||||||
print ("HTTP Connection Server ends.")
|
log ("HTTP Connection Server ends.")
|
||||||
end
|
end
|
||||||
rescue
|
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
|
if attached l_http_socket as ll_http_socket then
|
||||||
ll_http_socket.cleanup
|
ll_http_socket.cleanup
|
||||||
@@ -97,6 +98,18 @@ feature -- Inherited Features
|
|||||||
retry
|
retry
|
||||||
end
|
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
|
feature -- Event
|
||||||
|
|
||||||
on_launched (a_port: INTEGER)
|
on_launched (a_port: INTEGER)
|
||||||
@@ -121,7 +134,7 @@ feature -- Event
|
|||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
is_verbose: BOOLEAN
|
is_verbose: BOOLEAN
|
||||||
-- Is verbose for output messages.
|
-- Is verbose for output messages.
|
||||||
do
|
do
|
||||||
|
|||||||
@@ -7,9 +7,6 @@ note
|
|||||||
class
|
class
|
||||||
HTTP_SERVER
|
HTTP_SERVER
|
||||||
|
|
||||||
inherit
|
|
||||||
HTTP_SERVER_SHARED_CONFIGURATION
|
|
||||||
|
|
||||||
create
|
create
|
||||||
make
|
make
|
||||||
|
|
||||||
@@ -18,7 +15,6 @@ feature -- Initialization
|
|||||||
make (cfg: like configuration)
|
make (cfg: like configuration)
|
||||||
do
|
do
|
||||||
configuration := cfg
|
configuration := cfg
|
||||||
set_server_configuration (configuration)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
setup (a_http_handler: HTTP_HANDLER)
|
setup (a_http_handler: HTTP_HANDLER)
|
||||||
@@ -30,12 +26,7 @@ feature -- Initialization
|
|||||||
print ("Starting Web Application Server (port="+ configuration.http_server_port.out +"):%N")
|
print ("Starting Web Application Server (port="+ configuration.http_server_port.out +"):%N")
|
||||||
end
|
end
|
||||||
stop_requested := False
|
stop_requested := False
|
||||||
if configuration.force_single_threaded then
|
a_http_handler.execute
|
||||||
a_http_handler.execute
|
|
||||||
else
|
|
||||||
a_http_handler.launch
|
|
||||||
a_http_handler.join
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
shutdown_server
|
shutdown_server
|
||||||
|
|||||||
Reference in New Issue
Block a user