Extracted network socket classes from httpd folder, and created a new library/network/http_network library.
Renamed HTTPD_STREAM_SOCKET as HTTP_STREAM_SOCKET. Made http_client (net) library use the new http_network library.
This commit is contained in:
@@ -33,9 +33,9 @@ feature -- Access
|
||||
|
||||
feature {HTTPD_SERVER_I} -- Execution
|
||||
|
||||
accept_incoming_connection (a_listening_socket: HTTPD_STREAM_SOCKET)
|
||||
accept_incoming_connection (a_listening_socket: HTTP_STREAM_SOCKET)
|
||||
local
|
||||
cl: HTTPD_STREAM_SOCKET
|
||||
cl: HTTP_STREAM_SOCKET
|
||||
do
|
||||
is_shutdown_requested := is_shutdown_requested or shutdown_requested (server)
|
||||
if is_shutdown_requested then
|
||||
|
||||
@@ -64,19 +64,19 @@ feature {HTTPD_SERVER_I} -- Execution
|
||||
p.gracefull_stop
|
||||
end
|
||||
|
||||
accept_incoming_connection (a_listening_socket: HTTPD_STREAM_SOCKET)
|
||||
accept_incoming_connection (a_listening_socket: HTTP_STREAM_SOCKET)
|
||||
-- <Precursor>
|
||||
do
|
||||
accept_connection_on_pool (pool, a_listening_socket) -- Wait on not pool.is_full or is_stop_requested
|
||||
end
|
||||
|
||||
accept_connection_on_pool (a_pool: like pool; a_listening_socket: HTTPD_STREAM_SOCKET)
|
||||
accept_connection_on_pool (a_pool: like pool; a_listening_socket: HTTP_STREAM_SOCKET)
|
||||
-- Process accept connection
|
||||
-- note that the precondition matters for scoop synchronization.
|
||||
require
|
||||
concurrency: not a_pool.is_full or is_shutdown_requested or a_pool.stop_requested
|
||||
local
|
||||
cl: separate HTTPD_STREAM_SOCKET
|
||||
cl: separate HTTP_STREAM_SOCKET
|
||||
do
|
||||
debug ("dbglog")
|
||||
dbglog (generator + ".ENTER accept_connection_on_pool")
|
||||
@@ -121,7 +121,7 @@ feature {HTTPD_SERVER_I} -- Status report
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
separate_client_socket (hdl: separate HTTPD_REQUEST_HANDLER): separate HTTPD_STREAM_SOCKET
|
||||
separate_client_socket (hdl: separate HTTPD_REQUEST_HANDLER): separate HTTP_STREAM_SOCKET
|
||||
-- Client socket for request handler `hdl'.
|
||||
do
|
||||
Result := hdl.client_socket
|
||||
|
||||
@@ -51,9 +51,9 @@ feature {HTTPD_SERVER_I} -- Execution
|
||||
p.terminate
|
||||
end
|
||||
|
||||
accept_incoming_connection (a_listening_socket: HTTPD_STREAM_SOCKET)
|
||||
accept_incoming_connection (a_listening_socket: HTTP_STREAM_SOCKET)
|
||||
local
|
||||
cl: separate HTTPD_STREAM_SOCKET
|
||||
cl: separate HTTP_STREAM_SOCKET
|
||||
do
|
||||
debug ("dbglog")
|
||||
dbglog (generator + ".ENTER accept_connection {"+ a_listening_socket.descriptor.out +"}")
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="http_network" uuid="56DAA1CE-0A2E-451A-BFC9-7821578E79F0" library_target="http_network">
|
||||
<target name="http_network">
|
||||
<root all_classes="true"/>
|
||||
<file_rule>
|
||||
<exclude>/.git$</exclude>
|
||||
<exclude>/.svn$</exclude>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
</file_rule>
|
||||
<option warning="true" full_class_checking="false" is_attached_by_default="true" void_safety="all" syntax="standard">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="net" location="$ISE_LIBRARY\library\net\net-safe.ecf" readonly="false"/>
|
||||
<library name="net_ssl" location="$ISE_LIBRARY\unstable\library\network\socket\netssl\net_ssl-safe.ecf">
|
||||
<condition>
|
||||
<custom name="ssl_enabled" value="true"/>
|
||||
</condition>
|
||||
<condition>
|
||||
<custom name="net_ssl_enabled" value="true"/>
|
||||
</condition>
|
||||
<condition>
|
||||
<custom name="httpd_ssl_enabled" value="true"/>
|
||||
</condition>
|
||||
</library>
|
||||
<cluster name="network" location=".\network\">
|
||||
<file_rule>
|
||||
<exclude>/httpd_stream_socket_ext.e$</exclude>
|
||||
<condition>
|
||||
<version type="compiler" max="16.11.0.0"/>
|
||||
</condition>
|
||||
</file_rule>
|
||||
<cluster name="ssl_network" location="$|ssl\" recursive="true">
|
||||
<condition>
|
||||
<custom name="ssl_enabled" value="true"/>
|
||||
</condition>
|
||||
<condition>
|
||||
<custom name="net_ssl_enabled" value="true"/>
|
||||
</condition>
|
||||
<condition>
|
||||
<custom name="httpd_ssl_enabled" value="true"/>
|
||||
</condition>
|
||||
<file_rule>
|
||||
<exclude>/httpd_stream_ssl_socket_ext.e$</exclude>
|
||||
<condition>
|
||||
<version type="compiler" max="16.11.0.0"/>
|
||||
<custom name="ssl_enabled" value="true"/>
|
||||
</condition>
|
||||
<condition>
|
||||
<version type="compiler" max="16.11.0.0"/>
|
||||
<custom name="net_ssl_enabled" value="true"/>
|
||||
</condition>
|
||||
<condition>
|
||||
<version type="compiler" max="16.11.0.0"/>
|
||||
<custom name="httpd_ssl_enabled" value="true"/>
|
||||
</condition>
|
||||
</file_rule>
|
||||
</cluster>
|
||||
</cluster>
|
||||
<cluster name="network_until_16_05" location=".\network\until_16_05\" recursive="false">
|
||||
<condition>
|
||||
<version type="compiler" max="16.11.0.0"/>
|
||||
</condition>
|
||||
<cluster name="ssl_network_until_16_05" location="$|ssl\" recursive="true">
|
||||
<condition>
|
||||
<custom name="ssl_enabled" value="true"/>
|
||||
<version type="compiler" max="16.11.0.0"/>
|
||||
</condition>
|
||||
<condition>
|
||||
<custom name="net_ssl_enabled" value="true"/>
|
||||
<version type="compiler" max="16.11.0.0"/>
|
||||
</condition>
|
||||
<condition>
|
||||
<custom name="httpd_ssl_enabled" value="true"/>
|
||||
<version type="compiler" max="16.11.0.0"/>
|
||||
</condition>
|
||||
</cluster>
|
||||
</cluster>
|
||||
|
||||
</target>
|
||||
</system>
|
||||
@@ -1,81 +0,0 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-15-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-15-0 http://www.eiffel.com/developers/xml/configuration-1-15-0.xsd" name="http_network" uuid="56DAA1CE-0A2E-451A-BFC9-7821578E79F0" library_target="http_network">
|
||||
<target name="http_network">
|
||||
<root all_classes="true"/>
|
||||
<file_rule>
|
||||
<exclude>/.git$</exclude>
|
||||
<exclude>/.svn$</exclude>
|
||||
<exclude>/EIFGENs$</exclude>
|
||||
</file_rule>
|
||||
<option warning="true" full_class_checking="false" void_safety="none" syntax="standard">
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
|
||||
<library name="net" location="$ISE_LIBRARY\library\net\net.ecf"/>
|
||||
<library name="net_ssl" location="$ISE_LIBRARY\unstable\library\network\socket\netssl\net_ssl.ecf">
|
||||
<condition>
|
||||
<custom name="ssl_enabled" value="true"/>
|
||||
</condition>
|
||||
<condition>
|
||||
<custom name="net_ssl_enabled" value="true"/>
|
||||
</condition>
|
||||
<condition>
|
||||
<custom name="httpd_ssl_enabled" value="true"/>
|
||||
</condition>
|
||||
</library>
|
||||
<cluster name="network" location=".\network\">
|
||||
<file_rule>
|
||||
<exclude>/httpd_stream_socket_ext.e$</exclude>
|
||||
<condition>
|
||||
<version type="compiler" max="16.11.0.0"/>
|
||||
</condition>
|
||||
</file_rule>
|
||||
<cluster name="ssl_network" location="$|ssl\" recursive="true">
|
||||
<condition>
|
||||
<custom name="ssl_enabled" value="true"/>
|
||||
</condition>
|
||||
<condition>
|
||||
<custom name="net_ssl_enabled" value="true"/>
|
||||
</condition>
|
||||
<condition>
|
||||
<custom name="httpd_ssl_enabled" value="true"/>
|
||||
</condition>
|
||||
<file_rule>
|
||||
<exclude>/httpd_stream_ssl_socket_ext.e$</exclude>
|
||||
<condition>
|
||||
<version type="compiler" max="16.11.0.0"/>
|
||||
<custom name="ssl_enabled" value="true"/>
|
||||
</condition>
|
||||
<condition>
|
||||
<version type="compiler" max="16.11.0.0"/>
|
||||
<custom name="net_ssl_enabled" value="true"/>
|
||||
</condition>
|
||||
<condition>
|
||||
<version type="compiler" max="16.11.0.0"/>
|
||||
<custom name="httpd_ssl_enabled" value="true"/>
|
||||
</condition>
|
||||
</file_rule>
|
||||
</cluster>
|
||||
</cluster>
|
||||
<cluster name="network_until_16_05" location=".\network\until_16_05\" recursive="false">
|
||||
<condition>
|
||||
<version type="compiler" max="16.11.0.0"/>
|
||||
</condition>
|
||||
<cluster name="ssl_network_until_16_05" location="$|ssl\" recursive="true">
|
||||
<condition>
|
||||
<custom name="ssl_enabled" value="true"/>
|
||||
<version type="compiler" max="16.11.0.0"/>
|
||||
</condition>
|
||||
<condition>
|
||||
<custom name="net_ssl_enabled" value="true"/>
|
||||
<version type="compiler" max="16.11.0.0"/>
|
||||
</condition>
|
||||
<condition>
|
||||
<custom name="httpd_ssl_enabled" value="true"/>
|
||||
<version type="compiler" max="16.11.0.0"/>
|
||||
</condition>
|
||||
</cluster>
|
||||
</cluster>
|
||||
</target>
|
||||
</system>
|
||||
@@ -11,18 +11,8 @@
|
||||
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
|
||||
</option>
|
||||
<setting name="concurrency" value="scoop"/>
|
||||
<external_include location="$ECF_CONFIG_PATH/spec/include">
|
||||
<condition>
|
||||
<version type="compiler" min="16.11.0.0"/>
|
||||
</condition>
|
||||
</external_include>
|
||||
<external_include location="$ECF_CONFIG_PATH/spec/include_until_16_05">
|
||||
<condition>
|
||||
<version type="compiler" max="16.11.0.0"/>
|
||||
</condition>
|
||||
</external_include>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="http_network" location="http_network-safe.ecf" readonly="false"/>
|
||||
<library name="http_network" location="..\..\network\http_network\http_network-safe.ecf" readonly="false"/>
|
||||
<library name="net" location="$ISE_LIBRARY\library\net\net-safe.ecf"/>
|
||||
<library name="net_ssl" location="$ISE_LIBRARY\unstable\library\network\socket\netssl\net_ssl-safe.ecf">
|
||||
<condition>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
</option>
|
||||
<setting name="concurrency" value="thread"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
|
||||
<library name="http_network" location="http_network.ecf" readonly="false"/>
|
||||
<library name="http_network" location="..\..\network\http_network\http_network.ecf" readonly="false"/>
|
||||
<library name="net" location="$ISE_LIBRARY\library\net\net.ecf"/>
|
||||
<library name="net_ssl" location="$ISE_LIBRARY\unstable\library\network\socket\netssl\net_ssl.ecf">
|
||||
<condition>
|
||||
|
||||
@@ -39,7 +39,7 @@ feature {NONE} -- Access
|
||||
|
||||
feature {HTTPD_SERVER_I} -- Execution
|
||||
|
||||
accept_incoming_connection (a_listening_socket: HTTPD_STREAM_SOCKET)
|
||||
accept_incoming_connection (a_listening_socket: HTTP_STREAM_SOCKET)
|
||||
-- Accept incoming connection from `a_listening_socket'.
|
||||
deferred
|
||||
end
|
||||
|
||||
@@ -72,9 +72,9 @@ feature -- Status report
|
||||
|
||||
feature -- Access
|
||||
|
||||
internal_client_socket: detachable HTTPD_STREAM_SOCKET
|
||||
internal_client_socket: detachable HTTP_STREAM_SOCKET
|
||||
|
||||
client_socket: HTTPD_STREAM_SOCKET
|
||||
client_socket: HTTP_STREAM_SOCKET
|
||||
local
|
||||
s: like internal_client_socket
|
||||
do
|
||||
@@ -331,7 +331,7 @@ feature -- Execution
|
||||
|
||||
feature -- Request processing
|
||||
|
||||
process_request (a_socket: HTTPD_STREAM_SOCKET)
|
||||
process_request (a_socket: HTTP_STREAM_SOCKET)
|
||||
-- Process request on socket `a_socket'.
|
||||
require
|
||||
no_error: not has_error
|
||||
@@ -343,7 +343,7 @@ feature -- Request processing
|
||||
deferred
|
||||
end
|
||||
|
||||
process_bad_request (a_socket: HTTPD_STREAM_SOCKET)
|
||||
process_bad_request (a_socket: HTTP_STREAM_SOCKET)
|
||||
-- Process bad request catched on `a_socket'.
|
||||
require
|
||||
has_error: has_error
|
||||
@@ -378,7 +378,7 @@ feature -- Request processing
|
||||
|
||||
feature -- Parsing
|
||||
|
||||
get_request_header (a_socket: HTTPD_STREAM_SOCKET; a_is_reusing_connection: BOOLEAN)
|
||||
get_request_header (a_socket: HTTP_STREAM_SOCKET; a_is_reusing_connection: BOOLEAN)
|
||||
-- Analyze message extracted from `a_socket' as HTTP request.
|
||||
-- If `a_is_reusing_connection' is True, then first use
|
||||
-- Note: it reads from socket.
|
||||
@@ -504,7 +504,7 @@ feature -- Parsing
|
||||
end
|
||||
end
|
||||
|
||||
next_line (a_socket: HTTPD_STREAM_SOCKET): detachable STRING
|
||||
next_line (a_socket: HTTP_STREAM_SOCKET): detachable STRING
|
||||
-- Next line fetched from `a_socket' is available.
|
||||
-- note: may update `has_error'.
|
||||
require
|
||||
@@ -569,7 +569,7 @@ feature -- Output
|
||||
|
||||
feature {NONE} -- Helpers
|
||||
|
||||
socket_has_incoming_data (a_socket: HTTPD_STREAM_SOCKET): BOOLEAN
|
||||
socket_has_incoming_data (a_socket: HTTP_STREAM_SOCKET): BOOLEAN
|
||||
-- Is there any data to read on `a_socket' ?
|
||||
require
|
||||
a_socket.readable
|
||||
|
||||
@@ -151,7 +151,7 @@ feature -- Listening
|
||||
-- Creates a socket and connects to the http server.
|
||||
-- `a_server': The main server object
|
||||
local
|
||||
l_listening_socket: detachable HTTPD_STREAM_SOCKET
|
||||
l_listening_socket: detachable HTTP_STREAM_SOCKET
|
||||
l_http_port: INTEGER
|
||||
l_connection_handler: HTTPD_CONNECTION_HANDLER
|
||||
do
|
||||
@@ -234,7 +234,7 @@ feature -- Listening
|
||||
|
||||
feature {NONE} -- Factory
|
||||
|
||||
new_listening_socket (a_addr: detachable INET_ADDRESS; a_http_port: INTEGER): HTTPD_STREAM_SOCKET
|
||||
new_listening_socket (a_addr: detachable INET_ADDRESS; a_http_port: INTEGER): HTTP_STREAM_SOCKET
|
||||
do
|
||||
if a_addr /= Void then
|
||||
create Result.make_server_by_address_and_port (a_addr, a_http_port)
|
||||
|
||||
10
library/server/httpd/license.lic
Normal file
10
library/server/httpd/license.lic
Normal file
@@ -0,0 +1,10 @@
|
||||
${NOTE_KEYWORD}
|
||||
copyright: "2011-${YEAR}, 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
|
||||
]"
|
||||
@@ -1,243 +0,0 @@
|
||||
note
|
||||
description: "Summary description for {HTTPD_STREAM_SOCKET}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
HTTPD_STREAM_SOCKET
|
||||
|
||||
inherit
|
||||
NETWORK_STREAM_SOCKET
|
||||
|
||||
HTTPD_STREAM_SOCKET_EXT
|
||||
|
||||
create
|
||||
make, make_empty,
|
||||
make_client_by_port, make_client_by_address_and_port,
|
||||
make_server_by_port, make_server_by_address_and_port, make_loopback_server_by_port
|
||||
|
||||
create {NETWORK_STREAM_SOCKET}
|
||||
make_from_descriptor_and_address
|
||||
|
||||
feature -- Input
|
||||
|
||||
read_character_noexception
|
||||
-- Read a new character.
|
||||
-- Make result available in `last_character'.
|
||||
-- No exception raised!
|
||||
do
|
||||
read_to_managed_pointer_noexception (socket_buffer, 0, character_8_bytes)
|
||||
if bytes_read /= character_8_bytes then
|
||||
socket_error := "Peer closed connection"
|
||||
else
|
||||
last_character := socket_buffer.read_character (0)
|
||||
socket_error := Void
|
||||
end
|
||||
end
|
||||
|
||||
read_stream_noexception (nb_char: INTEGER)
|
||||
-- Read a string of at most `nb_char' characters.
|
||||
-- Make result available in `last_string'.
|
||||
local
|
||||
ext: C_STRING
|
||||
return_val: INTEGER
|
||||
do
|
||||
create ext.make_empty (nb_char + 1)
|
||||
return_val := c_read_stream_noexception (descriptor, nb_char, ext.item)
|
||||
bytes_read := return_val
|
||||
if return_val >= 0 then
|
||||
ext.set_count (return_val)
|
||||
last_string := ext.substring (1, return_val)
|
||||
else
|
||||
socket_error := "Peer error [0x" + return_val.to_hex_string + "]"
|
||||
last_string.wipe_out
|
||||
end
|
||||
end
|
||||
|
||||
read_to_managed_pointer_noexception (p: MANAGED_POINTER; start_pos, nb_bytes: INTEGER)
|
||||
-- Read at most `nb_bytes' bound bytes and make result
|
||||
-- available in `p' at position `start_pos'.
|
||||
-- No exception raised!
|
||||
do
|
||||
read_into_pointer_noexception (p.item, start_pos, nb_bytes)
|
||||
end
|
||||
|
||||
read_line_noexception
|
||||
-- Read a line of characters (ended by a new_line).
|
||||
-- No exception raised!
|
||||
local
|
||||
l_last_string: like last_string
|
||||
do
|
||||
create l_last_string.make (512)
|
||||
read_character_noexception
|
||||
from
|
||||
until
|
||||
last_character = '%N' or else was_error
|
||||
loop
|
||||
l_last_string.extend (last_character)
|
||||
read_character_noexception
|
||||
end
|
||||
last_string := l_last_string
|
||||
end
|
||||
|
||||
peek_stream_noexception (nb_char: INTEGER)
|
||||
-- Read a string of at most `nb_char' characters without removing the data from the queue.
|
||||
-- Make result available in last_string.
|
||||
-- No exception raised!
|
||||
require
|
||||
readable: readable
|
||||
socket_exists: exists
|
||||
local
|
||||
ext: C_STRING
|
||||
retval: INTEGER
|
||||
l: like last_string
|
||||
do
|
||||
create ext.make_empty (nb_char + 1)
|
||||
retval := c_recv_noexception (descriptor, ext.item, nb_char, c_peekmsg)
|
||||
if retval = 0 then
|
||||
last_string.wipe_out
|
||||
socket_error := Void
|
||||
elseif retval > 0 then
|
||||
ext.set_count (retval)
|
||||
l := last_string
|
||||
l.wipe_out
|
||||
l.grow (retval)
|
||||
l.set_count (retval)
|
||||
ext.read_substring_into (l, 1, retval)
|
||||
socket_error := Void
|
||||
else
|
||||
last_string.wipe_out
|
||||
socket_error := "Socket error (MSG_PEEK)"
|
||||
end
|
||||
ensure
|
||||
last_string_not_void: last_string /= Void
|
||||
end
|
||||
|
||||
feature {NONE} -- Input
|
||||
|
||||
read_into_pointer_noexception (p: POINTER; start_pos, nb_bytes: INTEGER_32)
|
||||
-- Read at most `nb_bytes' bound bytes and make result
|
||||
-- available in `p' at position `start_pos'.
|
||||
-- No exception raised!
|
||||
require
|
||||
p_not_void: p /= default_pointer
|
||||
nb_bytes_non_negative: nb_bytes >= 0
|
||||
is_readable: readable
|
||||
local
|
||||
l_read: INTEGER_32
|
||||
l_last_read: INTEGER_32
|
||||
do
|
||||
from
|
||||
l_last_read := 1
|
||||
until
|
||||
l_read = nb_bytes or l_last_read <= 0
|
||||
loop
|
||||
l_last_read := c_read_stream_noexception (descriptor, nb_bytes - l_read, p + start_pos + l_read)
|
||||
if l_last_read >= 0 then
|
||||
l_read := l_read + l_last_read
|
||||
end
|
||||
end
|
||||
bytes_read := l_read
|
||||
ensure
|
||||
bytes_read_updated: 0 <= bytes_read and bytes_read <= nb_bytes
|
||||
end
|
||||
|
||||
feature -- Output
|
||||
|
||||
bytes_sent: INTEGER
|
||||
-- Last number of bytes sent by `put_managed_pointer_noexception' (i.e `put_pointer_content_noexception').
|
||||
|
||||
put_managed_pointer_noexception (p: MANAGED_POINTER; start_pos, nb_bytes: INTEGER_32)
|
||||
-- Put data of length `nb_bytes' pointed by `start_pos' index in `p' at
|
||||
-- current position.
|
||||
-- Update `bytes_sent'.
|
||||
-- No exception raised!
|
||||
require
|
||||
p_not_void: p /= Void
|
||||
p_large_enough: p.count >= nb_bytes + start_pos
|
||||
nb_bytes_non_negative: nb_bytes >= 0
|
||||
extendible: extendible
|
||||
do
|
||||
put_pointer_content_noexception (p.item, start_pos, nb_bytes)
|
||||
end
|
||||
|
||||
put_pointer_content_noexception (a_pointer: POINTER; a_offset, a_byte_count: INTEGER)
|
||||
-- Write `a_byte_count' bytes to the socket.
|
||||
-- The data is taken from the memory area pointed to by `a_pointer', at offset `a_offset'.
|
||||
-- Update `bytes_sent'.
|
||||
-- No exception raised!
|
||||
require
|
||||
pointer_not_void: a_pointer /= default_pointer
|
||||
byte_count_non_negative: a_byte_count >= 0
|
||||
extendible: extendible
|
||||
local
|
||||
l_sent: INTEGER_32
|
||||
l_last_sent: INTEGER_32
|
||||
do
|
||||
from
|
||||
l_last_sent := 1
|
||||
until
|
||||
l_sent = a_byte_count or l_last_sent <= 0
|
||||
loop
|
||||
l_last_sent := c_put_stream_noexception (descriptor, a_pointer + a_offset + l_sent, a_byte_count - l_sent)
|
||||
if l_last_sent >= 0 then
|
||||
l_sent := l_sent + l_last_sent
|
||||
elseif l_sent < a_byte_count then
|
||||
socket_error := "No all bytes sent!"
|
||||
end
|
||||
end
|
||||
bytes_sent := l_sent
|
||||
ensure
|
||||
bytes_sent_updated: not was_error implies (0 <= bytes_sent and bytes_sent <= a_byte_count)
|
||||
end
|
||||
|
||||
put_character_noexception (c: CHARACTER)
|
||||
-- Write character `c' to socket.
|
||||
do
|
||||
socket_buffer.put_character (c, 0)
|
||||
put_managed_pointer_noexception (socket_buffer, 0, character_8_bytes)
|
||||
end
|
||||
|
||||
put_readable_string_8_noexception (s: READABLE_STRING_8)
|
||||
-- Write readable string `s' to socket.
|
||||
-- No exception raised!
|
||||
local
|
||||
ext: C_STRING
|
||||
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.
|
||||
local
|
||||
ext: C_STRING
|
||||
do
|
||||
create ext.make (s)
|
||||
put_managed_pointer (ext.managed_data, 0, s.count)
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
has_incoming_data: BOOLEAN
|
||||
-- Check if Current has available data to be read.
|
||||
-- note: no data will not be removed from the queue.
|
||||
require
|
||||
socket_exists: exists
|
||||
do
|
||||
peek_stream_noexception (1)
|
||||
Result := last_string.count = 1
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2015, Jocelyn Fiat, Javier Velilla, 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
|
||||
@@ -1,13 +0,0 @@
|
||||
note
|
||||
description: "[
|
||||
Extension to HTTPD_STREAM_SOCKET to support backward compatibility.
|
||||
|
||||
TO BE REMOVED IN THE FUTURE, WHEN 16.05 IS OLD.
|
||||
]"
|
||||
|
||||
deferred class
|
||||
HTTPD_STREAM_SOCKET_EXT
|
||||
|
||||
feature {NONE} -- No-Exception network operation
|
||||
|
||||
end
|
||||
@@ -1,149 +0,0 @@
|
||||
note
|
||||
description: "SSL tcp stream socket."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
HTTPD_STREAM_SSL_SOCKET
|
||||
|
||||
inherit
|
||||
HTTPD_STREAM_SOCKET
|
||||
undefine
|
||||
make_empty, make_from_descriptor_and_address,
|
||||
error_number,
|
||||
readstream, read_stream,
|
||||
read_into_pointer,
|
||||
read_to_managed_pointer,
|
||||
put_pointer_content,
|
||||
write, send,
|
||||
close_socket,
|
||||
connect, shutdown,
|
||||
do_accept
|
||||
redefine
|
||||
put_managed_pointer,
|
||||
read_stream_noexception,
|
||||
read_into_pointer_noexception,
|
||||
put_pointer_content_noexception
|
||||
end
|
||||
|
||||
SSL_NETWORK_STREAM_SOCKET
|
||||
redefine
|
||||
put_managed_pointer -- Redefine to allow support of compiler before 16.11.
|
||||
end
|
||||
|
||||
HTTPD_STREAM_SSL_SOCKET_EXT
|
||||
|
||||
create
|
||||
make, make_empty,
|
||||
make_client_by_port, make_client_by_address_and_port,
|
||||
make_server_by_port, make_server_by_address_and_port, make_loopback_server_by_port
|
||||
|
||||
create {SSL_NETWORK_STREAM_SOCKET}
|
||||
make_from_descriptor_and_address
|
||||
|
||||
feature -- Input
|
||||
|
||||
read_stream_noexception (nb_char: INTEGER)
|
||||
-- Read a string of at most `nb_char' characters.
|
||||
-- Make result available in `last_string'.
|
||||
local
|
||||
ext: C_STRING
|
||||
return_val: INTEGER
|
||||
do
|
||||
if
|
||||
attached context as l_context and then
|
||||
attached l_context.last_ssl as l_ssl
|
||||
then
|
||||
create ext.make_empty (nb_char + 1)
|
||||
return_val := l_ssl.read (ext.item , nb_char)
|
||||
bytes_read := return_val
|
||||
if return_val >= 0 then
|
||||
ext.set_count (return_val)
|
||||
last_string := ext.substring (1, return_val)
|
||||
else
|
||||
socket_error := "Peer error [0x" + return_val.to_hex_string + "]"
|
||||
last_string.wipe_out
|
||||
end
|
||||
else
|
||||
check has_context: False end
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Input
|
||||
|
||||
read_into_pointer_noexception (p: POINTER; start_pos, nb_bytes: INTEGER_32)
|
||||
-- Read at most `nb_bytes' bound bytes and make result
|
||||
-- available in `p' at position `start_pos'.
|
||||
-- No exception raised!
|
||||
local
|
||||
l_read: INTEGER
|
||||
l_last_read: INTEGER
|
||||
do
|
||||
if
|
||||
attached context as l_context and then
|
||||
attached l_context.last_ssl as l_ssl
|
||||
then
|
||||
from
|
||||
l_last_read := 1
|
||||
until
|
||||
l_read = nb_bytes or l_last_read <= 0
|
||||
loop
|
||||
l_last_read := l_ssl.read (p + start_pos + l_read, nb_bytes - l_read)
|
||||
if l_last_read >= 0 then
|
||||
l_read := l_read + l_last_read
|
||||
end
|
||||
end
|
||||
bytes_read := l_read
|
||||
else
|
||||
check has_context: False end
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Output
|
||||
|
||||
put_managed_pointer (p: MANAGED_POINTER; start_pos, nb_bytes: INTEGER)
|
||||
-- Put data of length `nb_bytes' pointed by `start_pos' index in `p' at
|
||||
-- current position.
|
||||
do
|
||||
Precursor {HTTPD_STREAM_SOCKET} (p, start_pos, nb_bytes)
|
||||
end
|
||||
|
||||
put_pointer_content_noexception (a_pointer: POINTER; a_offset, a_byte_count: INTEGER)
|
||||
-- Write `a_byte_count' bytes to the socket.
|
||||
-- The data is taken from the memory area pointed to by `a_pointer', at offset `a_offset'.
|
||||
-- Update `bytes_sent'.
|
||||
-- No exception raised!
|
||||
local
|
||||
l_bytes_sent: INTEGER
|
||||
do
|
||||
if
|
||||
attached context as l_context and then
|
||||
attached l_context.last_ssl as l_ssl
|
||||
then
|
||||
l_bytes_sent := ssl_write (l_ssl, a_pointer + a_offset, a_byte_count)
|
||||
if l_bytes_sent < a_byte_count then
|
||||
socket_error := "No all bytes sent!"
|
||||
end
|
||||
bytes_sent := l_bytes_sent
|
||||
else
|
||||
check has_last_ssl: False end
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_certificate_filenames (a_crt_filename, a_key_filename: detachable READABLE_STRING_GENERAL)
|
||||
do
|
||||
if a_crt_filename /= Void then
|
||||
set_certificate_file_name (a_crt_filename)
|
||||
end
|
||||
if a_key_filename /= Void then
|
||||
set_key_file_name (a_key_filename)
|
||||
end
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2013, Javier Velilla, Jocelyn Fiat and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
|
||||
end
|
||||
@@ -1,23 +0,0 @@
|
||||
note
|
||||
description: "[
|
||||
Extension to HTTPD_STREAM_SOCKET to support backward compatibility.
|
||||
|
||||
TO BE REMOVED IN THE FUTURE, WHEN 16.05 IS OLD.
|
||||
]"
|
||||
|
||||
deferred class
|
||||
HTTPD_STREAM_SSL_SOCKET_EXT
|
||||
|
||||
feature {NONE} -- SSL bridge
|
||||
|
||||
ssl_write (a_ssl: SSL; a_pointer: POINTER; a_byte_count: INTEGER): INTEGER
|
||||
do
|
||||
Result := a_ssl.write (a_pointer, a_byte_count)
|
||||
if a_ssl.was_error then
|
||||
if Result >= 0 then
|
||||
Result := -1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,160 +0,0 @@
|
||||
note
|
||||
description: "[
|
||||
Until 16.05, the EiffelNet socket interface DOES NOT have
|
||||
- make_server_by_address_and_port
|
||||
- recv_timeout
|
||||
- send_timeout.
|
||||
|
||||
TO BE REMOVED IN THE FUTURE, WHEN 16.05 IS OLD.
|
||||
]"
|
||||
|
||||
deferred class
|
||||
HTTPD_STREAM_SOCKET_EXT
|
||||
|
||||
inherit
|
||||
PLATFORM
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
make
|
||||
deferred
|
||||
end
|
||||
|
||||
make_server_by_address_and_port (a_address: INET_ADDRESS; a_port: INTEGER)
|
||||
-- Create server socket on `a_address' and `a_port'.
|
||||
require
|
||||
valid_port: a_port >= 0
|
||||
do
|
||||
make
|
||||
set_address (create {like address_type}.make_from_address_and_port (a_address, a_port))
|
||||
bind
|
||||
end
|
||||
|
||||
feature -- Basic operation
|
||||
|
||||
bind
|
||||
deferred
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
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
|
||||
|
||||
feature -- Socket Recv and Send timeout.
|
||||
|
||||
set_recv_timeout (a_timeout_seconds: INTEGER)
|
||||
-- Set the receive timeout in seconds on Current socket.
|
||||
-- if `0' the related operations will never timeout.
|
||||
require
|
||||
positive_timeout: a_timeout_seconds >= 0
|
||||
do
|
||||
c_set_sock_recv_timeout (descriptor, level_sol_socket, a_timeout_seconds)
|
||||
end
|
||||
|
||||
set_send_timeout (a_timeout_seconds: INTEGER)
|
||||
-- Set the send timeout in milliseconds on Current socket.
|
||||
-- if `0' the related operations will never timeout.
|
||||
require
|
||||
positive_timeout: a_timeout_seconds >= 0
|
||||
do
|
||||
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
|
||||
"C inline use %"ew_httpd_net.h%""
|
||||
alias
|
||||
"[
|
||||
#ifdef SO_RCVTIMEO
|
||||
int flag = SO_RCVTIMEO;
|
||||
#else
|
||||
int flag = 0x1006;
|
||||
#endif
|
||||
|
||||
#ifdef EIF_WINDOWS
|
||||
int arg = (int) 1000 * $a_timeout_seconds; /* Timeout in milliseconds */
|
||||
setsockopt((int) $a_fd, (int) $a_level, flag, (char *) &arg, sizeof(arg));
|
||||
#else
|
||||
struct timeval tv;
|
||||
tv.tv_sec = $a_timeout_seconds; /* Timeout in seconds */
|
||||
tv.tv_usec = 0;
|
||||
setsockopt((int) $a_fd, (int) $a_level, flag, (struct timeval *)&tv, sizeof(struct timeval));
|
||||
#endif
|
||||
]"
|
||||
end
|
||||
|
||||
c_set_sock_send_timeout (a_fd, a_level: INTEGER; a_timeout_seconds: INTEGER)
|
||||
-- C routine to set socket option `SO_SNDTIMEO' with `a_timeout_seconds' seconds.
|
||||
external
|
||||
"C inline use %"ew_httpd_net.h%""
|
||||
alias
|
||||
"[
|
||||
#ifdef SO_RCVTIMEO
|
||||
int flag = SO_SNDTIMEO;
|
||||
#else
|
||||
int flag = 0x1005;
|
||||
#endif
|
||||
#ifdef EIF_WINDOWS
|
||||
int arg = (int) 1000 * $a_timeout_seconds; /* Timeout in milliseconds */
|
||||
setsockopt((int) $a_fd, (int) $a_level, flag, (char *) &arg, sizeof(arg));
|
||||
#else
|
||||
struct timeval tv;
|
||||
tv.tv_sec = $a_timeout_seconds; /* Timeout in seconds */
|
||||
tv.tv_usec = 0;
|
||||
setsockopt((int) $a_fd, (int) $a_level, flag, (struct timeval *)&tv, sizeof(struct timeval));
|
||||
#endif
|
||||
]"
|
||||
end
|
||||
|
||||
feature {NONE} -- No-Exception network operation
|
||||
|
||||
c_recv_noexception (a_fd: INTEGER; buf: POINTER; len: INTEGER; flags: INTEGER): INTEGER
|
||||
-- External routine to read a `len' number of characters
|
||||
-- into buffer `buf' from socket `a_fd' with options `flags'.
|
||||
external
|
||||
"C inline use %"ew_httpd_net.h%""
|
||||
alias
|
||||
"[
|
||||
recv((int) $a_fd, (char *) $buf, (int) $len, (int) $flags)
|
||||
]"
|
||||
end
|
||||
|
||||
c_read_stream_noexception (a_fd: INTEGER; len: INTEGER; buf: POINTER): INTEGER
|
||||
-- External routine to read a `len' number of characters
|
||||
-- into buffer `buf' from socket `a_fd'.
|
||||
do
|
||||
Result := c_recv_noexception (a_fd, buf, len, 0)
|
||||
end
|
||||
|
||||
c_put_stream_noexception (a_fd: INTEGER; buf: POINTER; len: INTEGER): INTEGER
|
||||
-- External routine to write stream pointed by `s' of
|
||||
-- length `length' to socket `fd'.
|
||||
-- Note: does not raise exception on error, but return error value as Result.
|
||||
external
|
||||
"C inline use %"ew_httpd_net.h%""
|
||||
alias
|
||||
"[
|
||||
send((int) $a_fd, (char *) $buf, (int) $len, (int) 0)
|
||||
]"
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,41 +0,0 @@
|
||||
note
|
||||
description: "[
|
||||
Extension to HTTPD_STREAM_SOCKET to support backward compatibility.
|
||||
|
||||
TO BE REMOVED IN THE FUTURE, WHEN 16.05 IS OLD.
|
||||
]"
|
||||
|
||||
deferred class
|
||||
HTTPD_STREAM_SSL_SOCKET_EXT
|
||||
|
||||
feature {NONE} -- SSL bridge
|
||||
|
||||
ssl_write (a_ssl: SSL; a_pointer: POINTER; a_byte_count: INTEGER): INTEGER
|
||||
do
|
||||
-- In delivery until 16.05
|
||||
-- SSL.write does not return any value!
|
||||
-- So let's use `c_ssl_write' from Current class
|
||||
-- instead of:
|
||||
-- a_ssl.write (a_pointer, a_byte_count)
|
||||
|
||||
Result := c_ssl_write (a_ssl.ptr, a_pointer, a_byte_count)
|
||||
if a_ssl.was_error then
|
||||
-- Until 16.05, there is no error check for `SSL.write'
|
||||
-- so nothing can be done here.
|
||||
|
||||
if Result >= 0 then
|
||||
Result := -1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
c_ssl_write (an_ssl_ptr: POINTER; buffer: POINTER; nb_bytes: INTEGER_32): INTEGER_32
|
||||
-- External call to SSL_write
|
||||
-- (export status {NONE})
|
||||
external
|
||||
"C use %"eif_openssl.h%""
|
||||
alias
|
||||
"SSL_write"
|
||||
end
|
||||
|
||||
end
|
||||
@@ -8,7 +8,7 @@ deferred class
|
||||
|
||||
feature -- Access
|
||||
|
||||
new_client_socket (a_is_secure: BOOLEAN): HTTPD_STREAM_SOCKET
|
||||
new_client_socket (a_is_secure: BOOLEAN): HTTP_STREAM_SOCKET
|
||||
do
|
||||
check not_secure: not a_is_secure end
|
||||
create Result.make_empty
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
indexing
|
||||
description: "Functions used by the EiffelWeb httpd networking classes. "
|
||||
copyright: "Copyright (c) 2011-2016, Jocelyn Fiat, 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
|
||||
]"
|
||||
*/
|
||||
|
||||
#ifndef _ew_httpd_net_h_
|
||||
#define _ew_httpd_net_h_
|
||||
|
||||
#include "eif_config.h"
|
||||
|
||||
#ifdef EIF_WINDOWS
|
||||
# ifndef _WINSOCKAPI_
|
||||
# define FD_SETSIZE 256
|
||||
# include <winsock2.h>
|
||||
# include <Ws2tcpip.h>
|
||||
# include <stdio.h>
|
||||
# endif
|
||||
#else /* unix-specific */
|
||||
# include <sys/socket.h>
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* extern declarations ... */
|
||||
#ifdef EIF_WINDOWS
|
||||
extern int setsockopt(int, int, int, char*, int);
|
||||
extern int recv(int, char *, int, int);
|
||||
extern int send(int, char *, int, int);
|
||||
#else
|
||||
extern int setsockopt(int, int, int, const void*, socklen_t);
|
||||
extern ssize_t recv(int, void *, size_t, int);
|
||||
extern ssize_t send(int, const void *, size_t, int);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -19,7 +19,7 @@ create
|
||||
|
||||
feature {NONE} -- Factory
|
||||
|
||||
new_listening_socket (a_addr: detachable INET_ADDRESS; a_http_port: INTEGER): HTTPD_STREAM_SOCKET
|
||||
new_listening_socket (a_addr: detachable INET_ADDRESS; a_http_port: INTEGER): HTTP_STREAM_SOCKET
|
||||
local
|
||||
s_ssl: HTTPD_STREAM_SSL_SOCKET
|
||||
do
|
||||
|
||||
@@ -8,7 +8,7 @@ deferred class
|
||||
|
||||
feature -- Access
|
||||
|
||||
new_client_socket (a_is_secure: BOOLEAN): HTTPD_STREAM_SOCKET
|
||||
new_client_socket (a_is_secure: BOOLEAN): HTTP_STREAM_SOCKET
|
||||
do
|
||||
if a_is_secure then
|
||||
create {HTTPD_STREAM_SSL_SOCKET} Result.make_empty
|
||||
|
||||
Reference in New Issue
Block a user