Compare commits

..

3 Commits

Author SHA1 Message Date
f56aa22c29 Fixed compilation of proxy and simple examples.
Made the websocket client library scoop capable.
2016-12-05 15:56:46 +01:00
186e5514eb If the count for put_file_content is not positive (i.e <= 0), do not send anything.
Output/log more information for request handling when standalone httpd server has verbose enabled.
2016-12-01 21:20:14 +01:00
9fd53b9b1f Fixed debug.ecf file from debug example. 2016-12-01 21:08:13 +01:00
16 changed files with 68 additions and 236 deletions

View File

@@ -11,10 +11,6 @@
</option>
<setting name="console_application" value="true"/>
<setting name="concurrency" value="scoop"/>
<capability>
<concurrency support="scoop" use="scoop"/>
<void_safety support="all"/>
</capability>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="encoder" location="..\..\library\text\encoder\encoder-safe.ecf" readonly="false"/>
<library name="http" location="..\..\library\network\protocol\http\http-safe.ecf"/>
@@ -24,9 +20,6 @@
<target name="debug_any" extends="common">
<root class="EWF_DEBUG_SERVER" feature="make_and_launch"/>
<setting name="concurrency" value="scoop"/>
<capability>
<concurrency support="scoop" use="scoop"/>
</capability>
<library name="cgi" location="..\..\library\server\wsf\connector\cgi-safe.ecf" readonly="false"/>
<library name="libfcgi" location="..\..\library\server\wsf\connector\libfcgi-safe.ecf" readonly="false"/>
<library name="standalone" location="..\..\library\server\wsf\connector\standalone-safe.ecf" readonly="false"/>
@@ -36,9 +29,6 @@
<target name="debug_standalone" extends="common">
<root class="EWF_DEBUG_SERVER" feature="make_and_launch"/>
<setting name="concurrency" value="scoop"/>
<capability>
<concurrency support="scoop" use="scoop"/>
</capability>
<library name="default_standalone" location="..\..\library\server\wsf\default\standalone-safe.ecf" readonly="false"/>
<cluster name="launcher" location=".\launcher\default\" recursive="true"/>
<cluster name="src" location=".\src\" recursive="true"/>

View File

@@ -10,6 +10,7 @@
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option>
<setting name="console_application" value="true"/>
<setting name="concurrency" value="scoop"/>
<variable name="ssl_supported" value="false"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="http" location="..\..\library\network\protocol\http\http-safe.ecf"/>

View File

@@ -10,6 +10,7 @@
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option>
<setting name="console_application" value="true"/>
<setting name="concurrency" value="scoop"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="http" location="..\..\library\network\protocol\http\http-safe.ecf"/>
<library name="wsf" location="..\..\library\server\wsf\wsf-safe.ecf"/>

View File

@@ -22,13 +22,10 @@ create
feature {NONE} -- Initialization
initialize
local
opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS
do
Precursor
--| Uncomment the following 2 lines, to read options from "ewf.ini" configuration file
-- create {WSF_SERVICE_LAUNCHER_OPTIONS_FROM_INI} opts.make_from_file ("ewf.ini")
-- import_service_options (opts)
--| Uncomment the following line, to read options from "ewf.ini" configuration file
-- import_service_options (create {WSF_SERVICE_LAUNCHER_OPTIONS_FROM_INI} opts.make_from_file ("ewf.ini"))
end
launch (opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS)

View File

@@ -207,8 +207,6 @@ feature -- Output
put_character_noexception (c: CHARACTER)
-- Write character `c' to socket.
require
extendible: extendible
do
socket_buffer.put_character (c, 0)
put_managed_pointer_noexception (socket_buffer, 0, character_8_bytes)
@@ -219,15 +217,13 @@ feature -- Output
-- No exception raised!
local
ext: C_STRING
do
do
create ext.make (s)
put_managed_pointer_noexception (ext.managed_data, 0, s.count)
end
put_readable_string_8 (s: READABLE_STRING_8)
-- Write readable string `s' to socket.
require
extendible: extendible
local
ext: C_STRING
do
@@ -247,27 +243,6 @@ feature -- Status report
Result := last_string.count = 1
end
set_bytes_sent (nb: INTEGER)
-- Set `bytes_sent` to `nb`;
do
bytes_sent := nb
end
report_error (m: READABLE_STRING_8)
-- Report error, and set `socket_error` to `m`.
do
socket_error := m
end
feature -- Extension
socket: HTTP_STREAM_SOCKET
-- Associated socket.
do
Result := Current
end
note
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

View File

@@ -8,75 +8,6 @@ note
deferred class
HTTP_STREAM_SOCKET_EXT
feature -- Extension
feature {NONE} -- No-Exception network operation
socket: HTTP_STREAM_SOCKET
-- Associated socket.
-- Used to extend HTTP_STREAM_SOCKET with Current interface.
deferred
end
feature -- No-Exception network operation
put_file_content_with_timeout (a_file: FILE; a_offset: INTEGER; a_byte_count: INTEGER; a_timeout: INTEGER)
-- Send `a_count' bytes from the content of file `a_file' starting at offset `a_offset'.
-- When relevant, use the `a_timeout` to wait on completion (if a_timeout < 0, ignored)
require
a_file_closed_or_openread: a_file.exists and then (a_file.is_access_readable or a_file.is_closed)
byte_count_positive: a_byte_count > 0
extendible: socket.extendible
local
l_close_needed: BOOLEAN
l_bytes_sent: INTEGER
cs: C_STRING
do
if a_file.exists and then a_file.is_access_readable then
if a_file.is_open_read then
l_close_needed := False
else
l_close_needed := True
a_file.open_read
end
create cs.make (a_file.path.name)
l_bytes_sent := c_sendfile (socket.descriptor, a_file.file_pointer, a_offset, a_byte_count, a_timeout)
if l_bytes_sent < 0 then
socket.report_error ("Network error: sendfile")
end
socket.set_bytes_sent (l_bytes_sent)
if l_close_needed then
a_file.close
end
end
ensure
bytes_sent_updated: not socket.was_error implies (0 <= socket.bytes_sent and socket.bytes_sent <= a_byte_count)
end
put_file_content (a_file: FILE; a_offset: INTEGER; a_byte_count: INTEGER)
-- Send `a_count' bytes from the content of file `a_file' starting at offset `a_offset'.
-- When relevant, use the `a_timeout` to wait on completion (if a_timeout < 0, ignored)
do
put_file_content_with_timeout (a_file, a_offset, a_byte_count, -1)
end
feature {NONE} -- External
c_sendfile (a_fd: INTEGER; fp: POINTER; a_offset: INTEGER; len: INTEGER; a_timeout: INTEGER): INTEGER
-- External routine to write file content from `fp` of
-- length `len' to socket `a_fd'
-- note: On Windows, due to asynchronous potential behavior, wait for completion using `timeout` value.
-- EIF_INTEGER c_sendfile_noexception(EIF_INTEGER out_fd, FILE* f, EIF_INTEGER offset, EIF_INTEGER length, EIF_INTEGER timeout).
external
"C blocking"
end
note
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -26,22 +26,28 @@ feature -- Initialization
valid_port: a_port >= 0
do
make
socket.set_address (create {like socket.address_type}.make_from_address_and_port (a_address, a_port))
socket.bind
set_address (create {like address_type}.make_from_address_and_port (a_address, a_port))
bind
end
feature -- Extension
feature -- Basic operation
socket: HTTP_STREAM_SOCKET
-- Associated socket.
-- Used to extend HTTP_STREAM_SOCKET with Current interface.
bind
deferred
end
feature {NONE} -- Externals: socket option levels
feature -- Access
level_sol_socket: INTEGER_32
-- SOL_SOCKET level of options
set_address (addr: detachable like address_type)
deferred
end
address_type: NETWORK_SOCKET_ADDRESS
deferred
end
descriptor: INTEGER
-- Socket descriptor of current socket
deferred
end
@@ -53,7 +59,7 @@ feature -- Socket Recv and Send timeout.
require
positive_timeout: a_timeout_seconds >= 0
do
c_set_sock_recv_timeout (socket.descriptor, level_sol_socket, a_timeout_seconds)
c_set_sock_recv_timeout (descriptor, level_sol_socket, a_timeout_seconds)
end
set_send_timeout (a_timeout_seconds: INTEGER)
@@ -62,77 +68,16 @@ feature -- Socket Recv and Send timeout.
require
positive_timeout: a_timeout_seconds >= 0
do
c_set_sock_send_timeout (socket.descriptor, level_sol_socket, a_timeout_seconds)
end
feature -- Output
put_file_content_with_timeout (a_file: FILE; a_offset: INTEGER; a_byte_count: INTEGER; a_timeout_ms: INTEGER)
-- Send `a_count' bytes from the content of file `a_file' starting at offset `a_offset'.
-- When relevant, use the `a_timeout_ms` to wait on completion (if a_timeout < 0, ignored)
require
a_file_closed_or_openread: a_file.exists and then (a_file.is_access_readable or a_file.is_closed)
byte_count_positive: a_byte_count > 0
extendible: socket.extendible
local
l_close_needed: BOOLEAN
l_remain: INTEGER
l_done: BOOLEAN
s: STRING
l_bytes_sent: INTEGER
do
if a_file.exists and then a_file.is_access_readable then
if a_file.is_open_read then
l_close_needed := False
else
l_close_needed := True
a_file.open_read
end
if a_offset > 0 then
a_file.move (a_offset)
end
from
l_remain := a_byte_count
l_done := False
until
a_file.exhausted or l_done
loop
a_file.read_stream (l_remain.min (4_096))
s := a_file.last_string
if s.is_empty then
-- File error?
l_done := True
else
socket.put_string_8_noexception (s)
l_bytes_sent := l_bytes_sent + socket.bytes_sent
l_remain := l_remain - s.count
check l_remain >= 0 end
l_done := l_remain = 0
end
end
socket.set_bytes_sent (l_bytes_sent)
if l_close_needed then
a_file.close
end
end
ensure
bytes_sent_updated: not socket.was_error implies (0 <= socket.bytes_sent and socket.bytes_sent <= a_byte_count)
end
put_file_content (a_file: FILE; a_offset: INTEGER; a_byte_count: INTEGER)
-- Send `a_count' bytes from the content of file `a_file' starting at offset `a_offset'.
require
a_file_closed_or_openread: a_file.exists and then (a_file.is_access_readable or a_file.is_closed)
byte_count_positive: a_byte_count > 0
extendible: socket.extendible
do
put_file_content_with_timeout (a_file, a_offset, a_byte_count, -1)
ensure
bytes_sent_updated: not socket.was_error implies (0 <= socket.bytes_sent and socket.bytes_sent <= a_byte_count)
c_set_sock_send_timeout (descriptor, level_sol_socket, a_timeout_seconds)
end
feature {NONE} -- Externals
level_sol_socket: INTEGER
-- SOL_SOCKET level of options
deferred
end
c_set_sock_recv_timeout (a_fd, a_level: INTEGER; a_timeout_seconds: INTEGER)
-- C routine to set socket option `SO_RCVTIMEO' with `a_timeout_seconds' seconds.
external
@@ -212,14 +157,4 @@ feature {NONE} -- No-Exception network operation
]"
end
note
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Colin Adams, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -29,10 +29,8 @@ feature {NONE} -- Initialization
create ws_client.make_with_port ("ws://echo.websocket.org", 80, Void)
-- create ws_client.make_with_port ("ws://127.0.0.1", 9090, Void)
ws_client.launch
ws_client.join_all
execution_environment.sleep (5_000_000)
ws_client.execute
end
end

View File

@@ -7,9 +7,10 @@
<exclude>/CVS$</exclude>
<exclude>/EIFGENs$</exclude>
</file_rule>
<option warning="true" void_safety="all">
<option warning="true" void_safety="all">
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option>
<setting name="concurrency" value="scoop"/>
<setting name="console_application" value="true"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="web_socket_client" location="..\..\web_socket_client-safe.ecf" readonly="false"/>
@@ -17,7 +18,7 @@
</target>
<target name="ws_client" extends="common">
<root class="APPLICATION" feature="make"/>
<setting name="concurrency" value="thread"/>
<setting name="concurrency" value="scoop"/>
</target>
<target name="ws_client_ssl" extends="ws_client">
<variable name="ssl_enabled" value="true"/>

View File

@@ -23,11 +23,6 @@ inherit
WEB_SOCKET
THREAD
rename
make as thread_make
end
feature -- Initialization
initialize (a_uri: READABLE_STRING_GENERAL; a_protocols: detachable ITERABLE [STRING])
@@ -35,7 +30,6 @@ feature -- Initialization
require
is_valid_uri: is_valid_uri (a_uri)
do
thread_make
uri := a_uri
set_default_port
create protocol.make_empty
@@ -50,7 +44,6 @@ feature -- Initialization
require
is_valid_uri: is_valid_uri (a_uri)
do
thread_make
uri := a_uri
port := a_port
create protocol.make_empty
@@ -64,11 +57,9 @@ feature -- Initialization
require
is_valid_uri: is_valid_uri (a_host)
do
thread_make
uri := a_host + ":" + a_port.out + a_path
port := a_port
create protocol.make_empty
-- set_protocols (a_protocols)
create ready_state.make
socket := new_socket (port, host)
create server_handshake.make
@@ -98,8 +89,10 @@ feature -- Access
local
l_uri: URI
do
create l_uri.make_from_string (a_uri.as_string_8)
Result := l_uri.is_valid
if a_uri.is_valid_as_string_8 then
create l_uri.make_from_string (a_uri.to_string_8)
Result := l_uri.is_valid
end
end
server_handshake: WEB_SOCKET_HANDSHAKE_DATA

View File

@@ -17,7 +17,6 @@
<library name="lib_http_network" location="..\..\http_network\http_network-safe.ecf"/>
<library name="lib_web_socket_protocol" location="..\protocol\web_socket_protocol-safe.ecf"/>
<library name="net" location="$ISE_LIBRARY\library\net\net-safe.ecf"/>
<library name="thread" location="$ISE_LIBRARY\library\thread\thread-safe.ecf"/>
<library name="uri" location="$ISE_LIBRARY\library\text\uri\uri-safe.ecf"/>
<cluster name="web_socket_client" location=".\src\" recursive="true">
<file_rule>

View File

@@ -8,7 +8,7 @@
<exclude>/CVS$</exclude>
<exclude>/EIFGENs$</exclude>
</file_rule>
<option warning="true" void_safety="none">
<option warning="true" void_safety="none">
</option>
<setting name="concurrency" value="scoop"/>
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
@@ -17,7 +17,6 @@
<library name="lib_http_network" location="..\..\http_network\http_network.ecf"/>
<library name="lib_web_socket_protocol" location="..\protocol\web_socket_protocol.ecf"/>
<library name="net" location="$ISE_LIBRARY\library\net\net.ecf"/>
<library name="thread" location="$ISE_LIBRARY\library\thread\thread.ecf"/>
<library name="uri" location="$ISE_LIBRARY\library\text\uri\uri.ecf"/>
<cluster name="web_socket_client" location=".\src\" recursive="true">
<file_rule>

View File

@@ -12,9 +12,6 @@ class
inherit
WGI_OUTPUT_STREAM
redefine
put_file_content
end
HTTP_STATUS_CODE_MESSAGES
export
@@ -97,18 +94,6 @@ feature -- Output
last_target_call_succeed := not target.was_error
end
put_file_content (a_file: FILE; a_offset: INTEGER; a_byte_count: INTEGER)
-- Send `a_byte_count' bytes from the content of file `a_file' starting at offset `a_offset'.
do
if a_byte_count > 500_000 then
last_target_call_succeed := False
target.put_file_content (a_file, a_offset, a_byte_count)
last_target_call_succeed := not target.was_error
else
Precursor (a_file, a_offset, a_byte_count)
end
end
feature -- Status report
is_available: BOOLEAN

View File

@@ -106,7 +106,9 @@ feature -- Output operation
put_file_content (f: FILE; a_offset: INTEGER; a_count: INTEGER)
-- Send `a_count' bytes from the content of file `f' starting at offset `a_offset'.
do
output.put_file_content (f, a_offset, a_count)
if a_count > 0 then
output.put_file_content (f, a_offset, a_count)
end
end
flush

View File

@@ -170,6 +170,9 @@ feature -- Status change
-- Report error occurred, with optional message `m'.
do
has_error := True
if m /= Void and then is_verbose then
log (m.as_string_8, debug_level)
end
end
reset_error
@@ -313,7 +316,7 @@ feature -- Execution
is_persistent_connection_requested := False
else
if is_verbose then
log (request_header, information_level)
log_with_separation_line (request_header, information_level)
end
process_request (l_socket)
end
@@ -590,6 +593,26 @@ feature -- Output
logger_set: logger = a_logger
end
log_with_separation_line (m: STRING; a_level: INTEGER)
-- Log message `m'.
require
is_verbose: is_verbose
local
s: STRING
do
if is_verbose and (verbose_level & a_level) = a_level then
create s.make (m.count + 42)
s.append (create {STRING}.make_filled ('-', 40))
s.append_character ('%N')
s.append (m)
if attached logger as l_logger then
l_logger.log (s)
else
io.put_string (s + "%N")
end
end
end
log (m: STRING; a_level: INTEGER)
-- Log message `m'.
require

View File

@@ -389,8 +389,10 @@ feature -- Body
message_writable: message_writable
not_too_big: a_offset + a_count <= f.count
do
wgi_response.put_file_content (f, a_offset, a_count)
increment_transfered_content_length (a_count)
if a_count > 0 then
wgi_response.put_file_content (f, a_offset, a_count)
increment_transfered_content_length (a_count)
end
end
feature -- Chunk body