-
class
AbstractMessageIOGateway
(Return to index)
-
Interface representing an object that can send/receive PortableMessages via a PortableDataIO byte-stream.
Type:
Include file:
../../iogateway/AbstractMessageIOGateway.h
Synopsis:
Public methods:
- public
AbstractMessageIOGateway (PortableDataIO * io)
This object becomes the owner of (io) and will delete it later.
- public status_t
AddOutgoingMessage (const PortableMessageRef & messageRef)
Adds the given message reference to our list of outgoing messages
to send. Never blocks. Returns B_ERROR iff for some reason
the message can't be queued (out of memory?)
- public pure virtual status_t
DoInput ()
Reads some more bytes from the wire.
If enough bytes have been read to assemble one or more new PortableMessages,
the new PortableMessages will be available after this method returns by
calling GetNextIncomingMessage().
Tries not to block, but may (depending on implementation)
Returns B_NO_ERROR usually, or B_ERROR if the connection has been broken
or some other catastrophic condition has occurred.
- public pure virtual status_t
DoOutput ()
Writes some of our outgoing messages to the wire.
Not guaranteed to write all outgoing messages (it will try not to block)
or some other catastrophic condition has occurred.
- public bool
GetInputEnabled () const
Returns true iff this gateway is interested in new data arriving at its
socket. Default value is true.
- public status_t
GetNextIncomingMessage (PortableMessageRef & setRef)
Retrieves the next message from the incoming messages queue.
Returns B_ERROR iff the queue is empty (in which case setRef
will not be modified)
- public pure virtual bool
HasBytesToOutput () const
Returns true iff there are any PortableMessages that have been
added (with AddOutgoingMessage()) but not already sent across the PortableDataIO.
Always returns false if the connection has been closed or hosed.
- public bool
HasIncomingMessagesReady () const
Returns true iff there are any incoming PortableMessages ready to
be retrieved via GetNextIncomingMessage().
- public void
SetFlushOnEmpty (bool flush)
By default, the AbstractMessageIOGateway calls Flush() on its PortableDataIO's
output stream whenever the last outgoing message in the outgoing message queue
is sent. Call SetFlushOnEmpty(false) to inhibit this behavior (e.g. for bandwidth
efficiency when low message latency is not a requirement).
- public void
SetInputEnabled (bool enable)
Call this to enable/disable reading of new incoming data from the socket.
- public void
SetPools (PortableMessageRef::ItemPool * ioMessagePool, PortableMessageRef::RefPool * ioRefPool)
By default, the AbstractMessageIOGateway will use the PortableMessage class's
built-in message and message-ref pool objects to allocate its messages. This
is okay for single-threaded programs, but can lead to race conditions in multi-threaded
situations. In those cases, call SetPools() with your own separate or synchronized
pool objects to avoid trouble.
The pools may be set to NULL to disable object pooling entirely (i.e. use new/delete instead)
- public virtual
~AbstractMessageIOGateway ()
Protected methods: