deferred class SOCKET_INPUT_OUTPUT_STREAM
Summary
A stream backed by a socket. You cannot directly create such a stream; instead, use ACCESS.stream for an outbound connection; for an inbound connection, the stream is automatically created by the SOCKET_SERVER and passed to its handlers.
Direct parents
Inherit list: TERMINAL_INPUT_OUTPUT_STREAM
Insert list: SOCKET_HANDLER, STRING_HANDLER
Known children
Inherit list: CLIENT_SOCKET_INPUT_OUTPUT_STREAM, SERVER_SOCKET_INPUT_OUTPUT_STREAM
Class invariant
Overview
Features
{ANY}
{}
{FILTER_INPUT_STREAM}
{FILTER_OUTPUT_STREAM}
{FILTER}
{}
{}
{}
{ANY}
{}
{ANY}
{FILTER}
{ANY}
{}
{ANY}
{}
{STREAM_HANDLER}
{ANY}
{}
{RECYCLING_POOL}
  • recycle
    Do whatever needs to be done to free resources or recycle other objects when recycling this one
{}
  • dispose
    Action to be executed just before garbage collection reclaims an object.
{}
Skipping separators:
{ANY}
To read one number at a time:
{ANY}
To read one line or one word at a time:
{ANY}
Other features:
{ANY}
{}
{ANY}
{ANY}
{ANY}
{}
{ABSTRACT_STRING}
{ANY}
To write a number:
{ANY}
Other features:
{ANY}
{}
{}
is_connected: BOOLEAN
effective function
{ANY}
True if the stream is connected.
Only in that case can data be transferred via this stream.
is_remote_connected: BOOLEAN
effective function
{ANY}
can_read_character: BOOLEAN
effective function
{ANY}
Can be temporarily False because the socket does not yet have available data
require
  • is_connected
ensure
  • Result implies not end_of_input
can_read_line: BOOLEAN
effective function
{ANY}
require
  • is_connected
can_unread_character: BOOLEAN
effective function
{ANY}
require
  • is_connected
  • valid_last_character
valid_last_character: BOOLEAN
effective function
{ANY}
require
  • is_connected
end_of_input: BOOLEAN
effective function
{ANY}
end_of_input means the previous attempt in character reading failed because the end has been reached.
So last_character is not valid and you are not allowed to do any read attempt anymore.
Notes:
  • Just after a successful connect, end_of_input is always False because you did not yet read anything).
  • Once the end of input has been reached, this is definitive in that no more characters will ever be provided (but of course you can still come back if can_unread_character; end_of_input will be changed if you unread_character). In that, it is different from can_read_character which is only a temporary state.
Please refer to the Liberty Eiffel FAQ or tutorial/io examples.
disconnect
deferred procedure
{ANY}
Try to disconnect the stream.
Note that it *does not* ensure that the stream will effectively be disconnected (some terminal streams, for instance, are always connected) but the feature can be used to "shake off" filters.
require
      • is_connected
      • can_disconnect
      • is_connected
      • can_disconnect
      • is_connected
      • can_disconnect
      • is_connected
      • can_disconnect
ensure
  • not is_filtered
when_disconnect (handler: PROCEDURE[TUPLE 1[SOCKET_INPUT_OUTPUT_STREAM]])
effective procedure
{ANY}
error: STRING
effective function
{ANY}
set_blocking
effective procedure
{ANY}
set blocking read mode for the socket
set_nonblocking
effective procedure
{ANY}
set non blocking read mode for the socket
delay_read: BOOLEAN
writable attribute
{}
delayed_read
effective procedure
{}
require ensure
filtered_read_character
effective procedure
require
  • is_connected
  • can_read_character
filtered_unread_character
effective procedure
require
  • is_connected
  • can_unread_character
filtered_last_character: CHARACTER
effective function
require
  • is_connected
  • valid_last_character
filtered_read_line_in (buffer: STRING)
effective procedure
require
  • is_connected
  • buffer /= Void
filtered_read_available_in (buffer: STRING, limit: INTEGER_32)
effective procedure
require
  • is_connected
  • buffer /= Void
filtered_put_character (c: CHARACTER)
effective procedure
require
  • is_connected
  • can_put_character(c)
filtered_flush
effective procedure
require
  • is_connected
filtered_descriptor: INTEGER_32
effective function
Find the descriptor of the terminal stream...
Filters do not have descriptors of their own
require
      • is_connected
      • filtered_has_descriptor
      • is_connected
      • filtered_has_descriptor
      • is_connected
      • filtered_has_descriptor
      • is_connected
      • filtered_has_descriptor
filtered_has_descriptor: BOOLEAN
is True
constant attribute
True if the underlying terminal stream has a descriptor
require
      • is_connected
      • is_connected
      • is_connected
      • is_connected
filtered_stream_pointer: POINTER
effective function
Find the pointer of the terminal stream...
Filters do not have pointers of their own
require
      • is_connected
      • filtered_has_stream_pointer
      • is_connected
      • filtered_has_stream_pointer
      • is_connected
      • filtered_has_stream_pointer
      • is_connected
      • filtered_has_stream_pointer
filtered_has_stream_pointer: BOOLEAN
is False
constant attribute
True if the underlying terminal stream has a pointer
require
      • is_connected
      • is_connected
      • is_connected
      • is_connected
ensure_read
effective procedure
{}
Read some new data from the socket if it is available.
Does not read anything if all the already read data is not yet consumed. Set next_index to the index of the next character to be read.
require ensure
beginning_of_stream: BOOLEAN
writable attribute
{}
We are at the beginning of the stream (for correct implementation of can_unread_data)
end_of_stream: BOOLEAN
writable attribute
{}
All the available data was read (but new data may become available if sent by the client)
next_index: INTEGER_32
writable attribute
{}
Set by ensure_read to the index of the next character to read
fire_disconnect
effective procedure
{}
require
socket: SOCKET
deferred function
{}
make
effective procedure
{}
Should be called by the creation procedures after the socket is set (the assertions ensure just that)
require
  • called_by_heirs_constructors_only: not is_made
  • create_socket_first: socket /= Void
ensure
socket_disconnected (a_socket: SOCKET)
effective procedure
{}
require
made: BOOLEAN
writable attribute
{}
This flag makes sure that heirs call "make" in their creation procedure(s).
is_made: BOOLEAN
effective function
{}
A trick to be sure that made is not alive (therefore not generated) in boost mode.
index: INTEGER_32
writable attribute
{}
Index of the last read character
in_buffer: STRING
writable attribute
{}
out_buffer: STRING
writable attribute
{}
disconnect_handlers: FAST_ARRAY[PROCEDURE[TUPLE 1[SOCKET_INPUT_OUTPUT_STREAM]]]
writable attribute
{}
can_disconnect: BOOLEAN
is True
constant attribute
{ANY}
True if the stream can be safely disconnected (without data loss, etc.)
require
      • is_connected
      • is_connected
      • is_connected
      • is_connected
detach
effective procedure
{ANY}
Detach the input and the output
See also detach_input, detach_output.
ensure
  • not is_filtered
is_filtered: BOOLEAN
effective function
{ANY}
Is one of the input or output streams filtered?
See also is_input_filtered, is_output_filtered
set_filter (a_filter: FILTER)
effective procedure
{ANY}
Don't use (use set_input_filter or set_output_filter)
require
  • a_filter /= Void
ensure
  • filter = a_filter
new_url: URL
effective function
{}
ensure
  • Result /= Void
read_character
effective procedure
{ANY}
If read_character fail, end_of_input is set.
Else, use last_character. Read tutorial or io cluster documentation to learn the read_character usage pattern.
require
  • is_connected
  • not is_filtered and then can_read_character
ensure
read_line_in (buffer: STRING)
effective procedure
{ANY}
Same job as read_line but storage is directly done in buffer.
Read tutorial or io cluster documentation to learn the read_line usage pattern.
require
  • is_connected
  • not is_filtered and then can_read_line
  • buffer /= Void
read_available_in (buffer: STRING, limit: INTEGER_32)
effective procedure
{ANY}
Same job as read_available but storage is directly done in buffer.
The usage pattern is the same as for read_line.
require
  • is_connected
  • not is_filtered
  • buffer /= Void
  • limit > 0
unread_character
effective procedure
{ANY}
require
  • is_connected
  • not is_filtered and then can_unread_character
ensure
last_character: CHARACTER
effective function
{ANY}
require
  • is_connected
  • not end_of_input
  • not is_filtered and then valid_last_character
ensure
writable attribute
The filter that uses this stream as backend
event_can_read: EVENT_DESCRIPTOR
effective function
{ANY}
writable attribute
{}
descriptor: INTEGER_32
effective function
{ANY}
Some OS-dependent descriptor.
Mainly used by the sequencer library (see READY_CONDITION).
require
has_descriptor: BOOLEAN
effective function
{ANY}
True if that stream can be associated to some OS-meaningful descriptor.
require
url: URL
frozen
effective function
{ANY}
The URL to this stream as resource
ensure
  • not_void: Result /= Void
  • always_the_same: Result = url
url_memory: URL
writable attribute
{}
stream_pointer: POINTER
effective function
Some Back-end-dependent pointer (FILE* in C, InputStream or OutputStream in Java)
has_stream_pointer: BOOLEAN
effective function
True if that stream can be associated to some Back-end-meaningful stream pointer.
require
event_exception: EVENT_DESCRIPTOR
effective function
{ANY}
stream_exception: STREAM_EXCEPTION
writable attribute
{}
recycle
effective procedure
Do whatever needs to be done to free resources or recycle other objects when recycling this one
dispose
effective procedure
{}
Action to be executed just before garbage collection reclaims an object.
sequencer_descriptor (file: POINTER): INTEGER_32
{}
skip_separators
effective procedure
{ANY}
Skip all separators (see is_separator of class CHARACTER) and make the first non-separator available in last_character.
This non-separator character is pushed back into the stream (see unread_character) to be available one more time (the next read_character will consider this non-separator). When end_of_input occurs, this process is automatically stopped.
require
skip_separators_using (separators: STRING)
effective procedure
{ANY}
Same job as skip_separators using the separators set.
require
skip_remainder_of_line
effective procedure
{ANY}
Skip all the remainder of the line including the end of line delimiter itself.
read_integer
effective procedure
{ANY}
Read an integer according to the Eiffel syntax.
 Make result available in last_integer.  Heading
separators are automatically skipped using is_separator of class CHARACTER.  Trailing separators
are not skipped.
require ensure
last_integer: INTEGER_32
writable attribute
{ANY}
Last integer read using read_integer.
valid_last_integer: BOOLEAN
writable attribute
{ANY}
Was the last call to read_integer successful ?
last_real: REAL_64
writable attribute
{ANY}
Last real read with read_real.
valid_last_real: BOOLEAN
writable attribute
{ANY}
Was the last call to read_real successful ?
read_real
effective procedure
{ANY}
Read a REAL and make the result available in last_real.
require ensure
last_string: STRING
once function
{ANY}
Access to the unique common buffer to get for example the result computed by read_line, read_word, newline, etc.
This is a once function (the same common buffer is used for all streams).
read_line
effective procedure
{ANY}
Read a complete line ended by '%N' or end_of_input.%
% Make the result available in last_string common buffer. The end of line character (usually '%N') is not added in the last_string buffer. Read tutorial or io cluster documentation to learn the read_line usage pattern.
See also read_line_in.
require
read_available (limit: INTEGER_32)
effective procedure
{ANY}
Read as many characters as possible, as long as the stream does not block and up to the given limit.
read_word
effective procedure
{ANY}
Read a word using is_separator of class CHARACTER.
The result is available in the last_string common buffer. Heading separators are automatically skipped. Trailing separators are not skipped (last_character is left on the first one). If end_of_input is encountered, Result can be the empty string.
require
newline
effective procedure
{ANY}
Consume input until newline ('%N') is found.
% The corresponding STRING is stored in last_string common buffer.
require
reach_and_skip (keyword: STRING)
effective procedure
{ANY}
Try to skip enough characters in order to reach the keyword which is skipped too.
If the keyword is not in the remainder of this stream, the process is stopped as soon as end_of_input occurs.
require ensure
read_word_using (separators: STRING)
effective procedure
{ANY}
Same job as read_word using separators.
require
read_tail_in (str: STRING)
effective procedure
{ANY}
Read all remaining character of the stream in str.
require ensure
io_getc (stream: POINTER): INTEGER_32
{}
io_ungetc (byte: CHARACTER, stream: POINTER)
{}
io_fread (buf: NATIVE_ARRAY[CHARACTER], size: INTEGER_32, stream: POINTER): INTEGER_32
{}
return size read or 0 if end of input (-1 on error => exception ?)
{}
can_put_character (c: CHARACTER): BOOLEAN
effective function
{ANY}
put_character (c: CHARACTER)
effective procedure
{ANY}
require
  • is_connected
  • not is_filtered and then can_put_character(c)
flush
effective procedure
{ANY}
Flushes the pipe.
If output_is_filtered, calls the filter's flush instead.
require
  • is_connected
event_can_write: EVENT_DESCRIPTOR
effective function
{ANY}
writable attribute
{}
as_output_stream: OUTPUT_STREAM
effective function
{}
ensure
  • yes_indeed_it_is_the_same_object: Result.to_pointer = to_pointer
put_natively_stored_string (s: NATIVELY_STORED_STRING)
effective procedure
require
  • s /= Void
put_abstract_string (s: ABSTRACT_STRING)
effective procedure
require
  • s /= Void
put_string (s: ABSTRACT_STRING)
effective procedure
{ANY}
Output s to current output device.
require
put_unicode_string (unicode_string: UNICODE_STRING)
effective procedure
{ANY}
Output the UTF-8 encoding of the unicode_string.
require
put_line (s: ABSTRACT_STRING)
effective procedure
{ANY}
Output the string followed by a '%N'.
%
put_integer (i: INTEGER_64)
frozen
effective procedure
{ANY}
Output i to current output device.
put_integer_format (i: INTEGER_64, s: INTEGER_32)
frozen
effective procedure
{ANY}
Output i to current output device using at most s character.
put_natural_8 (n: NATURAL_8)
frozen
effective procedure
{ANY}
Output n to current output device.
put_natural_8_format (n: NATURAL_8, s: INTEGER_32)
frozen
effective procedure
{ANY}
Output n to current output device using at most s character.
put_natural_16 (n: NATURAL_16)
frozen
effective procedure
{ANY}
Output n to current output device.
put_natural_16_format (n: NATURAL_16, s: INTEGER_32)
frozen
effective procedure
{ANY}
Output n to current output device using at most s character.
put_natural_32 (n: NATURAL_32)
frozen
effective procedure
{ANY}
Output n to current output device.
put_natural_32_format (n: NATURAL_32, s: INTEGER_32)
frozen
effective procedure
{ANY}
Output n to current output device using at most s character.
put_natural_64 (n: NATURAL_64)
frozen
effective procedure
{ANY}
Output n to current output device.
put_natural_64_format (n: NATURAL_64, s: INTEGER_32)
frozen
effective procedure
{ANY}
Output n to current output device using at most s character.
put_real (r: REAL_64)
effective procedure
{ANY}
Output r to current output device.
put_real_format (r: REAL_64, f: INTEGER_32)
effective procedure
{ANY}
Output r with only f digit for the fractional part.
Examples:
   put_real(3.519,2) print "3.51".
require
put_real_scientific (r: REAL_64, f: INTEGER_32)
effective procedure
{ANY}
Output r using the scientific notation with only f digit for the fractional part.
Examples:
   put_real_scientific(3.519,2) print "3.16e+00".
require
put_number (number: NUMBER)
effective procedure
{ANY}
Output the number.
require
put_boolean (b: BOOLEAN)
effective procedure
{ANY}
Output b to current output device according to the Eiffel format.
put_pointer (p: POINTER)
effective procedure
{ANY}
Output a viewable version of p.
put_new_line
effective procedure
{ANY}
Output a newline character.
put_spaces (nb: INTEGER_32)
effective procedure
{ANY}
Output nb spaces character.
require
append_file (file_name: STRING)
effective procedure
{ANY}
require
tmp_file_read: TEXT_FILE_READ
once function
{}
tmp_string: STRING
once function
{}
io_putc (byte: CHARACTER, stream: POINTER)
{}
io_fwrite (buf: NATIVE_ARRAY[CHARACTER], size: INTEGER_32, stream: POINTER): INTEGER_32
{}
io_flush (stream: POINTER)
{}