added access to the effective port that the server is listening to (useful when we set port to 0 it use a random free port)
added verbose , so that we write message to the console only if desired.
This commit is contained in:
@@ -23,7 +23,7 @@ feature {NONE} -- Initialization
|
|||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
Server_details : STRING = "Server : NANO Eiffel Server"
|
Server_details : STRING = "Server : NINO Eiffel Server"
|
||||||
|
|
||||||
document_root: STRING assign set_document_root
|
document_root: STRING assign set_document_root
|
||||||
http_server_port: INTEGER assign set_http_server_port
|
http_server_port: INTEGER assign set_http_server_port
|
||||||
@@ -32,6 +32,9 @@ feature -- Access
|
|||||||
socket_connect_timeout: INTEGER assign set_socket_connect_timeout
|
socket_connect_timeout: INTEGER assign set_socket_connect_timeout
|
||||||
force_single_threaded: BOOLEAN assign set_force_single_threaded
|
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
|
feature -- Element change
|
||||||
|
|
||||||
set_http_server_port (v: like http_server_port)
|
set_http_server_port (v: like http_server_port)
|
||||||
@@ -64,6 +67,11 @@ feature -- Element change
|
|||||||
force_single_threaded := v
|
force_single_threaded := v
|
||||||
end
|
end
|
||||||
|
|
||||||
|
set_is_verbose (b: BOOLEAN)
|
||||||
|
-- Set `is_verbose' to `b'
|
||||||
|
do
|
||||||
|
is_verbose := b
|
||||||
|
end
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2011, Javier Velilla and others"
|
copyright: "2011-2011, Javier Velilla and others"
|
||||||
|
|||||||
@@ -38,21 +38,32 @@ feature -- Inherited Features
|
|||||||
l_http_socket: detachable TCP_STREAM_SOCKET
|
l_http_socket: detachable TCP_STREAM_SOCKET
|
||||||
l_http_port: INTEGER
|
l_http_port: INTEGER
|
||||||
do
|
do
|
||||||
|
launched := False
|
||||||
|
port := 0
|
||||||
is_stop_requested := False
|
is_stop_requested := False
|
||||||
l_http_port := main_server_configuration.http_server_port
|
l_http_port := main_server_configuration.http_server_port
|
||||||
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
|
||||||
print ("Socket could not be bound on port " + l_http_port.out )
|
print ("Socket could not be bound on port " + l_http_port.out )
|
||||||
|
end
|
||||||
else
|
else
|
||||||
|
l_http_port := l_http_socket.port
|
||||||
|
port := l_http_port
|
||||||
from
|
from
|
||||||
l_http_socket.listen (main_server_configuration.max_tcp_clients)
|
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
|
until
|
||||||
is_stop_requested
|
is_stop_requested
|
||||||
loop
|
loop
|
||||||
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
|
||||||
|
--| also handle permanent connection...?
|
||||||
receive_message_and_send_reply (l_thread_http_socket)
|
receive_message_and_send_reply (l_thread_http_socket)
|
||||||
l_thread_http_socket.cleanup
|
l_thread_http_socket.cleanup
|
||||||
check
|
check
|
||||||
@@ -67,7 +78,10 @@ feature -- Inherited Features
|
|||||||
socket_is_closed: l_http_socket.is_closed
|
socket_is_closed: l_http_socket.is_closed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
launched := False
|
||||||
|
if is_verbose then
|
||||||
print ("HTTP Connection Server ends.")
|
print ("HTTP Connection Server ends.")
|
||||||
|
end
|
||||||
rescue
|
rescue
|
||||||
print ("HTTP Connection Server shutdown due to exception. Please relaunch manually.")
|
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
|
socket_is_closed: ll_http_socket.is_closed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
launched := False
|
||||||
is_stop_requested := True
|
is_stop_requested := True
|
||||||
retry
|
retry
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
|
is_verbose: BOOLEAN
|
||||||
|
-- Is verbose for output messages.
|
||||||
|
do
|
||||||
|
Result := main_server_configuration.is_verbose
|
||||||
|
end
|
||||||
|
|
||||||
is_stop_requested: BOOLEAN
|
is_stop_requested: BOOLEAN
|
||||||
-- Set true to stop accept loop
|
-- Set true to stop accept loop
|
||||||
|
|
||||||
|
launched: BOOLEAN
|
||||||
|
-- Server launched and listening on `port'
|
||||||
|
|
||||||
|
port: INTEGER
|
||||||
|
-- Listening port.
|
||||||
|
--| 0: not launched
|
||||||
|
|
||||||
feature {NONE} -- Access
|
feature {NONE} -- Access
|
||||||
|
|
||||||
main_server: HTTP_SERVER
|
main_server: HTTP_SERVER
|
||||||
@@ -97,9 +125,6 @@ feature {NONE} -- Access
|
|||||||
Result := main_server.configuration
|
Result := main_server.configuration
|
||||||
end
|
end
|
||||||
|
|
||||||
Max_fragments: INTEGER = 1000
|
|
||||||
-- Defines the maximum number of fragments that can be received
|
|
||||||
|
|
||||||
feature -- Status setting
|
feature -- Status setting
|
||||||
|
|
||||||
shutdown
|
shutdown
|
||||||
@@ -114,7 +139,7 @@ feature -- Execution
|
|||||||
require
|
require
|
||||||
socket_attached: client_socket /= Void
|
socket_attached: client_socket /= Void
|
||||||
-- socket_valid: client_socket.is_open_read and then client_socket.is_open_write
|
-- 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
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ feature -- Initialization
|
|||||||
set_server_configuration (configuration)
|
set_server_configuration (configuration)
|
||||||
end
|
end
|
||||||
|
|
||||||
setup (a_http_handler : HTTP_HANDLER)
|
setup (a_http_handler: HTTP_HANDLER)
|
||||||
require
|
require
|
||||||
a_http_handler_valid: a_http_handler /= Void
|
a_http_handler_valid: a_http_handler /= Void
|
||||||
do
|
do
|
||||||
|
|||||||
Reference in New Issue
Block a user