Support persistent connection, even in single thread mode (i.e concurrency=none).
Warning: as there is no concurrent request handling in single threaded mode,
it is recommended to either set the keep_alive_timeout to a small value,
or disable persistent connection by setting max_keep_alive_requests to 0.
Change the default keep_alive_timeout from 15 to 5 seconds.
Accept -1 as value of max_keep_alive_requests to have unlimited number of request in the same persistent connection.
This commit is contained in:
@@ -3,9 +3,9 @@
|
|||||||
<target name="websocket_app">
|
<target name="websocket_app">
|
||||||
<root class="APPLICATION" feature="make_and_launch"/>
|
<root class="APPLICATION" feature="make_and_launch"/>
|
||||||
<file_rule>
|
<file_rule>
|
||||||
<exclude>/\.svn$</exclude>
|
|
||||||
<exclude>/CVS$</exclude>
|
<exclude>/CVS$</exclude>
|
||||||
<exclude>/EIFGENs$</exclude>
|
<exclude>/EIFGENs$</exclude>
|
||||||
|
<exclude>/\.svn$</exclude>
|
||||||
</file_rule>
|
</file_rule>
|
||||||
<option warning="true">
|
<option warning="true">
|
||||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||||
@@ -17,6 +17,14 @@
|
|||||||
<library name="wsf" location="..\..\library\server\wsf\wsf.ecf"/>
|
<library name="wsf" location="..\..\library\server\wsf\wsf.ecf"/>
|
||||||
<cluster name="app" location=".\" recursive="true"/>
|
<cluster name="app" location=".\" recursive="true"/>
|
||||||
</target>
|
</target>
|
||||||
|
<target name="websocket_app_st" extends="websocket_app">
|
||||||
|
<description>Single thread solution.
|
||||||
|
Warning: as it can not handle concurrent request, it is recommended to set Keep-Alive-Timeout to very low value, as browser will keep persistent connection open too long.
|
||||||
|
</description>
|
||||||
|
<capability>
|
||||||
|
<concurrency use="none"/>
|
||||||
|
</capability>
|
||||||
|
</target>
|
||||||
<target name="websocket_app_ssl" extends="websocket_app">
|
<target name="websocket_app_ssl" extends="websocket_app">
|
||||||
<variable name="ssl_enabled" value="true"/>
|
<variable name="ssl_enabled" value="true"/>
|
||||||
</target>
|
</target>
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ verbose=true
|
|||||||
verbose_level=INFORMATION
|
verbose_level=INFORMATION
|
||||||
port=9090
|
port=9090
|
||||||
max_concurrent_connections=100
|
max_concurrent_connections=100
|
||||||
keep_alive_timeout=35
|
keep_alive_timeout=2
|
||||||
|
max_keep_alive_requests=-1
|
||||||
max_tcp_clients=100
|
max_tcp_clients=100
|
||||||
socket_timeout=30
|
socket_timeout=30
|
||||||
socket_recv_timeout=5
|
socket_recv_timeout=5
|
||||||
max_keep_alive_requests=300
|
|
||||||
|
|
||||||
is_secure=false
|
is_secure=false
|
||||||
secure_certificate=ca.crt
|
secure_certificate=ca.crt
|
||||||
|
|||||||
@@ -8,19 +8,9 @@ deferred class
|
|||||||
|
|
||||||
inherit
|
inherit
|
||||||
HTTPD_REQUEST_HANDLER_I
|
HTTPD_REQUEST_HANDLER_I
|
||||||
redefine
|
|
||||||
is_persistent_connection_supported
|
|
||||||
end
|
|
||||||
|
|
||||||
feature -- Status report
|
|
||||||
|
|
||||||
is_persistent_connection_supported: BOOLEAN = False
|
|
||||||
-- <Precursor>
|
|
||||||
-- When there is no concurrency support, do not try to support
|
|
||||||
-- persistent connection!
|
|
||||||
|
|
||||||
note
|
note
|
||||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||||
source: "[
|
source: "[
|
||||||
Eiffel Software
|
Eiffel Software
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ feature -- Default timeout settings
|
|||||||
|
|
||||||
feature -- Default persistent connection settings
|
feature -- Default persistent connection settings
|
||||||
|
|
||||||
default_keep_alive_timeout: INTEGER = 15 -- seconds
|
default_keep_alive_timeout: INTEGER = 5 -- seconds
|
||||||
default_max_keep_alive_requests: INTEGER = 100
|
default_max_keep_alive_requests: INTEGER = 100
|
||||||
|
|
||||||
note
|
note
|
||||||
|
|||||||
@@ -140,7 +140,8 @@ feature -- Settings
|
|||||||
is_persistent_connection_supported: BOOLEAN
|
is_persistent_connection_supported: BOOLEAN
|
||||||
-- Is persistent connection supported?
|
-- Is persistent connection supported?
|
||||||
do
|
do
|
||||||
Result := {HTTPD_SERVER}.is_persistent_connection_supported and then max_keep_alive_requests > 0
|
Result := {HTTPD_SERVER}.is_persistent_connection_supported and then
|
||||||
|
max_keep_alive_requests /= 0 --| `-1` no limit
|
||||||
end
|
end
|
||||||
|
|
||||||
is_next_persistent_connection_supported: BOOLEAN
|
is_next_persistent_connection_supported: BOOLEAN
|
||||||
@@ -247,7 +248,8 @@ feature -- Execution
|
|||||||
l_exit
|
l_exit
|
||||||
loop
|
loop
|
||||||
n := n + 1
|
n := n + 1
|
||||||
if n >= m then
|
-- If `m` is `-1`, no limit for the number of keep_alive requests.
|
||||||
|
if m >= 0 and n >= m then
|
||||||
is_next_persistent_connection_supported := False
|
is_next_persistent_connection_supported := False
|
||||||
elseif n > 1 and is_verbose then
|
elseif n > 1 and is_verbose then
|
||||||
log ("Reuse connection (" + n.out + ")", information_level)
|
log ("Reuse connection (" + n.out + ")", information_level)
|
||||||
|
|||||||
@@ -104,11 +104,26 @@ feature -- Access: persistent connection
|
|||||||
-- Maximum number of requests allowed per persistent connection.
|
-- Maximum number of requests allowed per persistent connection.
|
||||||
-- Recommended a high setting.
|
-- Recommended a high setting.
|
||||||
-- To disable KeepAlive, set `max_keep_alive_requests' to 0.
|
-- To disable KeepAlive, set `max_keep_alive_requests' to 0.
|
||||||
|
-- To have no limit, set `max_keep_alive_requests' to -1.
|
||||||
-- By default: {HTTPD_CONFIGURATION_I}.default_max_keep_alive_requests .
|
-- By default: {HTTPD_CONFIGURATION_I}.default_max_keep_alive_requests .
|
||||||
do
|
do
|
||||||
Result := option_integer_value ("max_keep_alive_requests", 0)
|
Result := option_integer_value ("max_keep_alive_requests", 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
persistent_connection_disabled: BOOLEAN
|
||||||
|
-- Persistent connection disabled?
|
||||||
|
-- (or Keep-Alive disabled).
|
||||||
|
do
|
||||||
|
Result := max_keep_alive_requests = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
has_unlimited_keep_alive_requests: BOOLEAN
|
||||||
|
-- Has unlimited count of keep alive requests.
|
||||||
|
-- i.e no limit of number of requests allowed per persistent connection.
|
||||||
|
do
|
||||||
|
Result := max_keep_alive_requests < 0
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Access: SSL
|
feature -- Access: SSL
|
||||||
|
|
||||||
is_secure: BOOLEAN assign set_is_secure
|
is_secure: BOOLEAN assign set_is_secure
|
||||||
@@ -205,6 +220,16 @@ feature -- Element change
|
|||||||
set_numeric_option ("max_keep_alive_requests", nb)
|
set_numeric_option ("max_keep_alive_requests", nb)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
set_unlimited_keep_alive_requests
|
||||||
|
do
|
||||||
|
set_max_keep_alive_requests (-1)
|
||||||
|
end
|
||||||
|
|
||||||
|
disable_persistent_connection
|
||||||
|
do
|
||||||
|
set_max_keep_alive_requests (0)
|
||||||
|
end
|
||||||
|
|
||||||
set_is_secure (b: BOOLEAN)
|
set_is_secure (b: BOOLEAN)
|
||||||
-- Set secured connection enabled to `b'.
|
-- Set secured connection enabled to `b'.
|
||||||
-- i.e if connection is using SSL/TLS.
|
-- i.e if connection is using SSL/TLS.
|
||||||
|
|||||||
Reference in New Issue
Block a user