- REQUIRED METHODS
- PROVIDED METHODS
Tangence::Stream - base class for
Tangence stream-handling mixins
It provides the basic layer of message serialisation, deserialisation, and dispatching to methods that would handle the messages. Higher level classes are used to wrap this functionallity, and provide implementations of methods to handle the messages received.
When a message is received, it will be passed to a method whose name depends on the code of message received. The name will be
handle_request_, followed by the name of the message code, in uppercase; for example
The following methods are required to be implemented by some class using this mixin.
$stream->tangence_write( $data )
Write bytes of data to the connected peer.
$data will be a plain perl string.
$stream->handle_request_$CODE( $token, $message )
Invoked on receipt of a given message code.
$token will be some opaque perl scalar value, and
$message will be an instance of Tangence::Message.
The value of the token has no particular meaning, other than to be passed to the
The following methods are provided by this mixin.
Informs the object that the underlying connection has now been closed, and any attachments to
Tangence::ObjectProxy instances should now be dropped.
$stream->tangence_readfrom( $buffer )
Informs the object that more data has been read from the underlying connection stream. Whole messages will be removed from the beginning of the
$buffer, which should be passed as a direct scalar (because it will be modified). This method will invoke the required
handle_request_* methods. Any bytes remaining that form the start of a partial message will be left in the buffer.
$stream->request( %args )
Serialises a message object to pass to the
tangence_write method, then enqueues a response handler to be invoked when a reply arrives. Takes the following named arguments:
- request => Tangence::Message
The message body
- on_response => CODE
CODE reference to the callback to be invoked when a response to the message is received. It will be passed the response message:
$on_response->( $message )
$response = $stream->request( request => $request )->get
When called in non-void context, this method returns a Future that will yield the response instead. In this case it should not be given an
In this form, a
MSG_ERROR response will automatically turn into a failed Future; the subsequent
on_done code will not have to handle this case.
$stream->respond( $token, $message )
Serialises a message object to be sent to the
tangence_write method. The
$token value that was passed to the
handle_request_ method ensures that it is sent at the correct position in the stream, to allow the peer to pair it with the corresponding request.
$ver = $stream->minor_version
Returns the minor version negotiated by the
MSG_INITED initial message handshake.
Paul Evans <email@example.com>