Merge pull request #9 from jocelyn/master
Removed main thread and removed shared configuration class
This commit is contained in:
@@ -9,6 +9,8 @@ class
|
||||
inherit
|
||||
ARGUMENTS
|
||||
|
||||
HTTP_SERVER_SHARED_CONFIGURATION
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
@@ -24,6 +26,7 @@ feature {NONE} -- Initialization
|
||||
create l_cfg.make
|
||||
l_cfg.http_server_port := 9_000
|
||||
l_cfg.document_root := default_document_root
|
||||
set_server_configuration (l_cfg)
|
||||
debug ("nino")
|
||||
l_cfg.set_is_verbose (True)
|
||||
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)
|
||||
|
||||
@@ -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
|
||||
end
|
||||
|
||||
shutdown_server
|
||||
|
||||
Reference in New Issue
Block a user