Fixed setting of socket.timeout in httpd (was not currently set before).

Adopted the nanoseconds timeout precision
 - in config file added support for ns, us, ms, s timeout precision (without indication, it uses `seconds` precision).
This commit is contained in:
2018-10-29 11:27:26 +01:00
parent 9fcd30b4e1
commit d3e865cf6c
9 changed files with 267 additions and 81 deletions

View File

@@ -11,6 +11,8 @@ inherit
HTTPD_CONSTANTS
SOCKET_TIMEOUT_UTILITIES
feature {NONE} -- Initialization
make
@@ -18,9 +20,9 @@ feature {NONE} -- Initialization
http_server_port := default_http_server_port
max_concurrent_connections := default_max_concurrent_connections
max_tcp_clients := default_max_tcp_clients
socket_timeout := default_socket_timeout
socket_recv_timeout := default_socket_recv_timeout
keep_alive_timeout := default_keep_alive_timeout
socket_timeout_ns := seconds_to_nanoseconds (default_socket_timeout)
socket_recv_timeout_ns := seconds_to_nanoseconds (default_socket_recv_timeout)
keep_alive_timeout_ns := seconds_to_nanoseconds (default_keep_alive_timeout)
max_keep_alive_requests := default_max_keep_alive_requests
is_secure := False
create secure_certificate.make_empty
@@ -39,12 +41,12 @@ feature -- Access
max_tcp_clients: INTEGER assign set_max_tcp_clients
-- Listen on socket for at most `queue' connections.
socket_timeout: INTEGER assign set_socket_timeout
socket_timeout_ns: NATURAL_64 assign set_socket_timeout_ns
-- Amount of seconds that the server waits for receipts and transmissions during communications.
-- note: with timeout of 0, socket can wait for ever.
-- By default: 60 seconds, which is appropriate for most situations.
socket_recv_timeout: INTEGER assign set_socket_recv_timeout
socket_recv_timeout_ns: NATURAL_64 assign set_socket_recv_timeout_ns
-- Amount of seconds that the server waits for receiving data during communications.
-- note: with timeout of 0, socket can wait for ever.
-- By default: 5 seconds.
@@ -65,7 +67,7 @@ feature -- Access
verbose_level: INTEGER assign set_verbose_level
-- Verbosity of output.
keep_alive_timeout: INTEGER assign set_keep_alive_timeout
keep_alive_timeout_ns: NATURAL_64 assign set_keep_alive_timeout_ns
-- Persistent connection timeout.
-- Number of seconds the server waits after a request has been served before it closes the connection.
-- Timeout unit in Seconds.
@@ -86,9 +88,9 @@ feature -- Access
do
Result.is_verbose := is_verbose
Result.verbose_level := verbose_level
Result.timeout := socket_timeout
Result.socket_recv_timeout := socket_recv_timeout
Result.keep_alive_timeout := keep_alive_timeout
Result.timeout_ns := socket_timeout_ns
Result.socket_recv_timeout_ns := socket_recv_timeout_ns
Result.keep_alive_timeout_ns := keep_alive_timeout_ns
Result.max_keep_alive_requests := max_keep_alive_requests
Result.is_secure := is_secure
end
@@ -166,28 +168,52 @@ feature -- Element change
max_concurrent_connections_set : max_concurrent_connections = v
end
set_socket_timeout (a_nb_seconds: like socket_timeout)
set_socket_timeout_ns (a_nano_seconds: like socket_timeout_ns)
-- Set `socket_timeout_ns' with `a_nano_seconds'.
require
is_valid_timeout_ns: is_valid_timeout_ns (a_nano_seconds)
do
socket_timeout_ns := a_nano_seconds
ensure
socket_timeout_ns_set: socket_timeout_ns = a_nano_seconds
end
set_socket_recv_timeout_ns (a_nano_seconds: like socket_recv_timeout_ns)
-- Set `socket_recv_timeout_ns' with `a_nano_seconds'.
require
is_valid_timeout_ns: is_valid_timeout_ns (a_nano_seconds)
do
socket_recv_timeout_ns := a_nano_seconds
ensure
socket_recv_timeout_ns_set: socket_recv_timeout_ns = a_nano_seconds
end
set_keep_alive_timeout_ns (a_nano_seconds: like keep_alive_timeout_ns)
-- Set `keep_alive_timeout_ns' with `a_nano_seconds'.
require
is_valid_timeout_ns: is_valid_timeout_ns (a_nano_seconds)
do
keep_alive_timeout_ns := a_nano_seconds
ensure
keep_alive_timeout_ns_set: keep_alive_timeout_ns = a_nano_seconds
end
set_socket_timeout (a_nb_seconds: INTEGER)
-- Set `socket_timeout' with `a_nb_seconds'.
do
socket_timeout := a_nb_seconds
ensure
socket_timeout_set: socket_timeout = a_nb_seconds
set_socket_timeout_ns (seconds_to_nanoseconds (a_nb_seconds))
end
set_socket_recv_timeout (a_nb_seconds: like socket_recv_timeout)
set_socket_recv_timeout (a_nb_seconds: INTEGER)
-- Set `socket_recv_timeout' with `a_nb_seconds'.
do
socket_recv_timeout := a_nb_seconds
ensure
socket_recv_timeout_set: socket_recv_timeout = a_nb_seconds
set_socket_recv_timeout_ns (seconds_to_nanoseconds (a_nb_seconds))
end
set_keep_alive_timeout (a_seconds: like keep_alive_timeout)
-- Set `keep_alive_timeout' with `a_seconds'.
set_keep_alive_timeout (a_nb_seconds: INTEGER)
-- Set `keep_alive_timeout' with `a_nb_seconds'.
do
keep_alive_timeout := a_seconds
ensure
keep_alive_timeout_set: keep_alive_timeout = a_seconds
set_keep_alive_timeout_ns (seconds_to_nanoseconds (a_nb_seconds))
end
set_max_keep_alive_requests (nb: like max_keep_alive_requests)

View File

@@ -9,6 +9,9 @@ note
expanded class
HTTPD_REQUEST_SETTINGS
inherit
SOCKET_TIMEOUT_UTILITIES
feature -- Access
is_verbose: BOOLEAN assign set_is_verbose
@@ -20,13 +23,13 @@ feature -- Access
is_secure: BOOLEAN assign set_is_secure
-- Is using secure connection? i.e SSL?
timeout: INTEGER assign set_timeout
timeout_ns: NATURAL_64 assign set_timeout_ns
-- Amount of seconds that the server waits for receipts and transmissions during communications.
socket_recv_timeout: INTEGER assign set_socket_recv_timeout
socket_recv_timeout_ns: NATURAL_64 assign set_socket_recv_timeout_ns
-- Amount of seconds that the server waits for receiving data on socket during communications.
keep_alive_timeout: INTEGER assign set_keep_alive_timeout
keep_alive_timeout_ns: NATURAL_64 assign set_keep_alive_timeout_ns
-- Keep-alive timeout, also known as persistent-connection timeout.
-- Number of seconds the server waits after a request has been served before it closes the connection.
-- Unit in Seconds.
@@ -34,6 +37,29 @@ feature -- Access
max_keep_alive_requests: INTEGER assign set_max_keep_alive_requests
-- Maximum number of requests allowed per persistent connection.
feature -- Access: obsolete
timeout: INTEGER assign set_timeout
obsolete
"Use `timeout_ns` [2018-10-29]"
do
Result := nanoseconds_to_seconds (timeout_ns)
end
socket_recv_timeout: INTEGER assign set_socket_recv_timeout
obsolete
"Use `socket_recv_timeout_ns` [2018-10-29]"
do
Result := nanoseconds_to_seconds (socket_recv_timeout_ns)
end
keep_alive_timeout: INTEGER assign set_keep_alive_timeout
obsolete
"Use `keep_alive_timeout_ns` [2018-10-29]"
do
Result := nanoseconds_to_seconds (keep_alive_timeout_ns)
end
feature -- Change
set_is_verbose (b: BOOLEAN)
@@ -54,24 +80,48 @@ feature -- Change
is_secure := b
end
feature -- Timeout change
set_timeout_ns (a_timeout_in_nanoseconds: NATURAL_64)
-- Set `timeout_ns' to `a_timeout_in_nanoseconds'.
do
timeout_ns := a_timeout_in_nanoseconds
end
set_socket_recv_timeout_ns (a_timeout_in_nanoseconds: NATURAL_64)
-- Set `socket_recv_timeout_ns' to `a_timeout_in_nanoseconds'.
do
socket_recv_timeout_ns := a_timeout_in_nanoseconds
end
set_keep_alive_timeout_ns (a_timeout_in_nanoseconds: NATURAL_64)
-- Set `keep_alive_timeout_ns' to `a_timeout_in_nanoseconds'.
do
keep_alive_timeout_ns := a_timeout_in_nanoseconds
end
feature -- Timeout change (in seconds)
set_timeout (a_timeout_in_seconds: INTEGER)
-- Set `timeout' to `a_timeout_in_seconds'.
do
timeout := a_timeout_in_seconds
set_timeout_ns (seconds_to_nanoseconds (a_timeout_in_seconds))
end
set_socket_recv_timeout (a_timeout_in_seconds: INTEGER)
-- Set `socket_recv_timeout' to `a_timeout_in_seconds'.
do
socket_recv_timeout := a_timeout_in_seconds
set_socket_recv_timeout_ns (seconds_to_nanoseconds (a_timeout_in_seconds))
end
set_keep_alive_timeout (a_timeout_in_seconds: INTEGER)
-- Set `keep_alive_timeout' to `a_timeout_in_seconds'.
do
keep_alive_timeout := a_timeout_in_seconds
set_keep_alive_timeout_ns (seconds_to_nanoseconds (a_timeout_in_seconds))
end
feature -- Change
set_max_keep_alive_requests (nb: like max_keep_alive_requests)
-- Set `max_keep_alive_requests' with `nb'
do
@@ -79,7 +129,7 @@ feature -- Change
end
note
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
copyright: "2011-2018, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software

View File

@@ -19,9 +19,9 @@ feature {NONE} -- Initialization
do
reset
-- Import global request settings.
timeout := a_request_settings.timeout -- seconds
socket_recv_timeout := a_request_settings.socket_recv_timeout -- seconds
keep_alive_timeout := a_request_settings.keep_alive_timeout -- seconds
timeout_ns := a_request_settings.timeout_ns -- nanoseconds
socket_recv_timeout_ns := a_request_settings.socket_recv_timeout_ns -- nanoseconds
keep_alive_timeout_ns := a_request_settings.keep_alive_timeout_ns -- nanoseconds
max_keep_alive_requests := a_request_settings.max_keep_alive_requests
is_verbose := a_request_settings.is_verbose
@@ -140,7 +140,7 @@ feature -- Settings
is_persistent_connection_supported: BOOLEAN
-- Is persistent connection supported?
do
Result := {HTTPD_SERVER}.is_persistent_connection_supported and then
Result := {HTTPD_SERVER}.is_persistent_connection_supported and then
max_keep_alive_requests /= 0 --| `-1` no limit
end
@@ -148,16 +148,16 @@ feature -- Settings
-- Is next persistent connection supported?
-- note: it is relevant only if `is_persistent_connection_supported' is True.
timeout: INTEGER -- seconds
timeout_ns: NATURAL_64 -- nanoseconds
-- Amount of seconds that the server waits for receipts and transmissions during communications.
socket_recv_timeout: INTEGER -- seconds
socket_recv_timeout_ns: NATURAL_64 -- nanoseconds
-- Amount of seconds that the server waits for receiving data on socket during communications.
max_keep_alive_requests: INTEGER
-- Maximum number of requests allowed per persistent connection.
keep_alive_timeout: INTEGER -- seconds
keep_alive_timeout_ns: NATURAL_64 -- nanoseconds
-- Number of seconds for persistent connection timeout.
feature -- Status report
@@ -173,7 +173,7 @@ feature -- Status change
has_error := True
if m /= Void and then is_verbose then
log (m.as_string_8, debug_level)
end
end
end
reset_error
@@ -226,6 +226,10 @@ feature -- Execution
do
l_socket := client_socket
-- Set to expected `timeout_ns`.
l_socket.set_timeout_ns (timeout_ns)
l_socket.set_recv_timeout_ns (socket_recv_timeout_ns)
-- Compute remote info once for the persistent connection.
create l_remote_info
if attached l_socket.peer_address as l_addr then
@@ -407,9 +411,9 @@ feature -- Parsing
a_socket.readable
then
if a_is_reusing_connection then
a_socket.set_recv_timeout (keep_alive_timeout) -- in seconds!
a_socket.set_recv_timeout_ns (keep_alive_timeout_ns) -- in nanoseconds!
else
a_socket.set_recv_timeout (socket_recv_timeout) -- FIXME: return a 408 Request Timeout response ..
a_socket.set_recv_timeout_ns (socket_recv_timeout_ns) -- FIXME: return a 408 Request Timeout response ..
end
if
@@ -424,7 +428,7 @@ feature -- Parsing
if not has_error then
if a_is_reusing_connection then
-- Restore normal recv timeout!
a_socket.set_recv_timeout (socket_recv_timeout) -- FIXME: return a 408 Request Timeout response ..
a_socket.set_recv_timeout_ns (socket_recv_timeout_ns) -- FIXME: return a 408 Request Timeout response ..
end
from
line := next_line (a_socket)
@@ -646,7 +650,7 @@ invariant
request_header_attached: request_header /= Void
note
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
copyright: "2011-2018, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software

View File

@@ -109,9 +109,9 @@ feature -- Execution
log (" - port = " + configuration.http_server_port.out)
log (" - max_tcp_clients = " + configuration.max_tcp_clients.out)
log (" - max_concurrent_connections = " + configuration.max_concurrent_connections.out)
log (" - socket_timeout = " + configuration.socket_timeout.out + " seconds")
log (" - socket_recv_timeout = " + configuration.socket_recv_timeout.out + " seconds")
log (" - keep_alive_timeout = " + configuration.keep_alive_timeout.out + " seconds")
log (" - socket_timeout = " + timeout_representation (configuration.socket_timeout_ns))
log (" - socket_recv_timeout = " + timeout_representation (configuration.socket_recv_timeout_ns))
log (" - keep_alive_timeout = " + timeout_representation (configuration.keep_alive_timeout_ns))
log (" - max_keep_alive_requests = " + configuration.max_keep_alive_requests.out)
if configuration.has_secure_support then
if configuration.is_secure then
@@ -366,8 +366,25 @@ feature -- Output
end
end
timeout_representation (a_ns: NATURAL_64): STRING
do
if 1_000 * (a_ns // 1_000) = a_ns then
if 1_000_000 * (a_ns // 1_000_000) = a_ns then
if 1_000_000_000 * (a_ns // 1_000_000_000) = a_ns then
Result := (a_ns // 1_000_000_000).out + " seconds"
else
Result := (a_ns // 1_000_000).out + " milliseconds"
end
else
Result := (a_ns // 1_000).out + " microseconds"
end
else
Result := a_ns.out + " nanoseconds"
end
end
note
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
copyright: "2011-2018, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software