Class stream is a super-class for the class process and class socket and provides methods for sending data to child processes and over sockets as well as handling (asynchronous) input from these objects. The most commonly used functionality of this class is:
->format: Format text and send
it to the stream
->input_message:
Handle input record
->record_separator:
Separate input in records (regex
object)
<-record_separator
and stream<-input_message.<-record_separator)
is available, this code is executed with the following bindings:
@receiver: the stream object @arg1: a string object holding the data
Note: when using a socket
object, the receiver of the stream->input_message
must be @receiver
as the actual connections are running on a
object<-clone’ed
socket.
<-read_line.<-read_line.|int*<-input_message.
If the data arriving from the stream contains multiple records, the
stream<-input_message
will be called with each record separately.
The default record separator is’\n’(newline),
which implies that input is split into physical lines.
If stream<-record_separator
is an integer, the input is split into records of the indicated size.
This is useful for receiving binary data that is organised in records.
If you just want to collect all data from the process, it is advised
to set the stream<-record_separator
to @nil,
disabling the input filtering.
The stream->record_separator
may be changed on an open connection. Changing the record separator will
immediately scan the data in the input buffer and dispatch any complete
record according to the new definition. Setting the separator to @nil
will run the stream<-input_message
using the data in the buffer and destroy the buffer.
->newline, stream->append_line
and stream->format.|int]
<-input_message.
\n’, splitting the input into
physical lines. See stream<-record_separator.
Class stream is designed to share code between class socket and class process. It may be used for other interaction, but all such application of this class is as yet unsupported.
->close_input
and stream->close_output.append mode, using Prolog's stream
primitives to send data to an XPCE stream. For example:
open(Socket, append, Stream), format(Socket, 'Hello World~n', []), close(Stream).
Note: streams cannot be opened in mode write as they
lack the required source_sink->truncate_as_file
method.
This method fails if it reaches the end of the input (see also
stream->end_of_file.
The constant @nil
is returned if no full line becomes available within timeout
seconds. The granularity of timeout timing is system dependant. If the timeout
is @default,
this method blocks forever.
Asynchronous input handling (using stream->input_message)
is the preferred way of handling process data.