First step to improve a bit error handling related to socket disconnection.

Mainly in standalone connector for now.
This commit is contained in:
2015-04-01 17:29:53 +02:00
parent 9d20e85c03
commit 89e26519e4
12 changed files with 82 additions and 13 deletions

View File

@@ -70,8 +70,13 @@ feature -- Status writing
end end
end end
feature -- Status report
is_available: BOOLEAN = True
-- <Precursor>
note note
copyright: "2011-2011, Eiffel Software and others" copyright: "2011-2015, 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

View File

@@ -38,6 +38,11 @@ feature -- Status report
Result := True Result := True
end end
feature -- Status report
is_available: BOOLEAN = True
-- <Precursor>
feature -- Status writing feature -- Status writing
put_status_line (a_code: INTEGER; a_reason_phrase: detachable READABLE_STRING_8) put_status_line (a_code: INTEGER; a_reason_phrase: detachable READABLE_STRING_8)
@@ -100,7 +105,7 @@ invariant
fcgi_attached: fcgi /= Void fcgi_attached: fcgi /= Void
note note
copyright: "2011-2011, Eiffel Software and others" copyright: "2011-2015, 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

View File

@@ -79,6 +79,15 @@ feature -- Status report
Result := target.is_open_write Result := target.is_open_write
end end
feature -- Status report
is_available: BOOLEAN
-- <Precursor>
-- FIXME: see how "standalone" connection is doing that.
do
Result := target.is_open_read
end
feature -- Basic operations feature -- Basic operations
flush flush
@@ -86,7 +95,7 @@ feature -- Basic operations
end end
note note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" copyright: "2011-2015, 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

View File

@@ -70,8 +70,13 @@ feature -- Status writing
end end
end end
feature -- Status report
is_available: BOOLEAN = True
-- <Precursor>
note note
copyright: "2011-2011, Eiffel Software and others" copyright: "2011-2015, 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

View File

@@ -176,6 +176,7 @@ feature -- Execution
l_remote_info: detachable like remote_info l_remote_info: detachable like remote_info
l_continue: BOOLEAN l_continue: BOOLEAN
l_socket: like client_socket l_socket: like client_socket
l_ready_for_reading: BOOLEAN
do do
l_socket := client_socket l_socket := client_socket
check check
@@ -190,9 +191,11 @@ feature -- Execution
debug ("dbglog") debug ("dbglog")
dbglog (generator + ".execute_request socket=" + l_socket.descriptor.out + " ENTER") dbglog (generator + ".execute_request socket=" + l_socket.descriptor.out + " ENTER")
end end
l_socket.set_timeout (5) -- 5 seconds!
from until l_continue loop from until l_continue loop
if l_socket.try_ready_for_reading then -- Use timeout from l_socket!
-- ready_for_reading then l_ready_for_reading := l_socket.ready_for_reading
if l_ready_for_reading then
l_continue := True l_continue := True
create l_remote_info create l_remote_info
if attached l_socket.peer_address as l_addr then if attached l_socket.peer_address as l_addr then

View File

@@ -46,12 +46,27 @@ feature {NONE} -- Initialization
do do
Result := s.socket.descriptor Result := s.socket.descriptor
end end
feature -- Change feature -- Change
set_timeout (n: INTEGER)
do
if attached {NETWORK_STREAM_SOCKET} socket as l_socket then
l_socket.set_timeout (n)
end
end
set_connect_timeout (n: INTEGER)
do
if attached {NETWORK_STREAM_SOCKET} socket as l_socket then
l_socket.set_connect_timeout (n)
end
end
set_accept_timeout (n: INTEGER) set_accept_timeout (n: INTEGER)
do do
if attached {NETWORK_STREAM_SOCKET} socket as l_socket then if attached {NETWORK_STREAM_SOCKET} socket as l_socket then
l_socket.set_accept_timeout (500_000) l_socket.set_accept_timeout (n)
end end
end end

View File

@@ -62,7 +62,7 @@ feature -- Request processing
-- Process request ... -- Process request ...
local local
l_input: WGI_INPUT_STREAM l_input: WGI_INPUT_STREAM
l_output: WGI_OUTPUT_STREAM l_output: detachable WGI_OUTPUT_STREAM
l_error: WGI_ERROR_STREAM l_error: WGI_ERROR_STREAM
req: WGI_REQUEST_FROM_TABLE req: WGI_REQUEST_FROM_TABLE
res: detachable WGI_STANDALONE_RESPONSE_STREAM res: detachable WGI_STANDALONE_RESPONSE_STREAM
@@ -84,12 +84,15 @@ feature -- Request processing
res.push res.push
exec.clean exec.clean
else else
process_rescue (res) if not has_error then
process_rescue (res)
end
if exec /= Void then if exec /= Void then
exec.clean exec.clean
end end
end end
rescue rescue
has_error := l_output = Void or else not l_output.is_available
if not retried then if not retried then
retried := True retried := True
retry retry

View File

@@ -26,6 +26,7 @@ feature {NONE} -- Initialization
make (a_target: like target) make (a_target: like target)
do do
set_target (a_target) set_target (a_target)
last_target_call_succeed := True
end end
feature {WGI_STANDALONE_CONNECTOR, WGI_SERVICE} -- Nino feature {WGI_STANDALONE_CONNECTOR, WGI_SERVICE} -- Nino
@@ -37,6 +38,9 @@ feature {WGI_STANDALONE_CONNECTOR, WGI_SERVICE} -- Nino
target: HTTPD_STREAM_SOCKET target: HTTPD_STREAM_SOCKET
last_target_call_succeed: BOOLEAN
-- Last target call succeed?
feature -- Status writing feature -- Status writing
put_status_line (a_code: INTEGER; a_reason_phrase: detachable READABLE_STRING_8) put_status_line (a_code: INTEGER; a_reason_phrase: detachable READABLE_STRING_8)
@@ -65,22 +69,35 @@ feature -- Output
put_readable_string_8 (s: READABLE_STRING_8) put_readable_string_8 (s: READABLE_STRING_8)
-- Send `s' to http client -- Send `s' to http client
do do
last_target_call_succeed := False
target.put_readable_string_8 (s) target.put_readable_string_8 (s)
last_target_call_succeed := True
end end
put_string (s: READABLE_STRING_8) put_string (s: READABLE_STRING_8)
-- Send `s' to http client -- Send `s' to http client
do do
last_target_call_succeed := False
target.put_readable_string_8 (s) target.put_readable_string_8 (s)
last_target_call_succeed := True
end end
put_character (c: CHARACTER_8) put_character (c: CHARACTER_8)
do do
last_target_call_succeed := False
target.put_character (c) target.put_character (c)
last_target_call_succeed := True
end end
feature -- Status report feature -- Status report
is_available: BOOLEAN
-- <Precursor>
-- for instance IO failure due to socket disconnection.
do
Result := not last_target_call_succeed
end
is_open_write: BOOLEAN is_open_write: BOOLEAN
-- Can items be written to output stream? -- Can items be written to output stream?
do do

View File

@@ -10,6 +10,7 @@
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/> <library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="connector_standalone" location="standalone-safe.ecf" readonly="false"/> <library name="connector_standalone" location="standalone-safe.ecf" readonly="false"/>
<library name="ewsgi" location="..\..\ewsgi-safe.ecf" readonly="false"/> <library name="ewsgi" location="..\..\ewsgi-safe.ecf" readonly="false"/>
<library name="httpd" location="src\httpd\httpd-safe.ecf" readonly="false"/>
<library name="wsf" location="..\..\..\wsf\wsf-safe.ecf" readonly="false"/> <library name="wsf" location="..\..\..\wsf\wsf-safe.ecf" readonly="false"/>
<cluster name="tests" location="tests\" recursive="true"/> <cluster name="tests" location="tests\" recursive="true"/>
</target> </target>

View File

@@ -1,6 +1,6 @@
note note
description: "[ description: "[
WGI response acting as a filter. WGI response acting as a filter.
]" ]"
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
@@ -147,7 +147,7 @@ feature -- Error reporting
end end
note note
copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" copyright: "2011-2015, 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

View File

@@ -74,6 +74,12 @@ feature -- Status writing
feature -- Status report feature -- Status report
is_available: BOOLEAN
-- Is output available?
--| i.e: no issue with associated output stream, like closed socket, or related?
deferred
end
is_open_write: BOOLEAN is_open_write: BOOLEAN
-- Can items be written to output stream? -- Can items be written to output stream?
deferred deferred
@@ -93,7 +99,7 @@ feature -- Constant
crlf: STRING = "%R%N" crlf: STRING = "%R%N"
note note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" copyright: "2011-2015, 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

View File

@@ -128,7 +128,7 @@ feature {NONE} -- Implementation: Access
-- Server output channel -- Server output channel
;note ;note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" copyright: "2011-2015, 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