Merge pull request #5 from jocelyn/master

Please pull this change
This commit is contained in:
jvelilla
2011-11-03 10:27:27 -07:00
3 changed files with 42 additions and 9 deletions

View File

@@ -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"

View File

@@ -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

View File

@@ -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