-
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 PortableQueue<PortableMessageRef> &
GetIncomingMessageQueue ()
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)
Returns a reference to our incoming message list. Use of this method is discouraged,
but it can be useful.
- 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 virtual
~AbstractMessageIOGateway ()
Protected methods:
- protected bool
EnsureBufferSize (uint8 ** bufPtr, size_t * bufSize, size_t desiredSize, size_t copySize)
Allocates or reallocates a buffer so that when this method returns,
the buffer is at least (desiredSize) bytes long.
(bufPtr) points to a pointer to the buffer. (May point to a NULL
pointer if a buffer hasn't been allocated yet)
(bufSize) points to the current size of the buffer.
(desiredSize) indicates the minimum buffer size required.
(copySize) indicates the number of bytes to copy out of the
old buffer and into the new one, if a reallocation is necessary
Returns true on success, false on failure (out of memory)
- protected virtual void
GetPulseTime (const struct timeval & now, struct timeval & returnTime)
Returns NULL (may be overridden if Pulse() calls are desired)
- protected virtual void
Pulse (const struct timeval & now)
No-op. Will be called at the time(s) specified by GetPulseTime().
(now) is the current time.
- protected void
ReschedulePulseTime ()
Same as above, only the new pulse time isn't specified explicitely;
rather, it will be determined by calling GetPulseTime().
- protected void
ReschedulePulseTime (const struct timeval & pulseTime)
This can be used if you previously returned a pulse time
in (GetPulseTime()) and have since changed your mind, and don't
want to wait until your previously scheduled time to change it.
Call this to set the new time that you wish Pulse() to be called at.
- protected bool
_flushOnEmpty
- protected bool
_hosed
- protected PortableQueue<PortableMessageRef>
_incomingMessages
- protected bool
_inputEnabled
- protected PortableDataIO *
_io
- protected PortableMessageRef::ItemPool *
_ioMessagePool
- protected PortableMessageRef::RefPool *
_ioRefPool
- protected struct timeval
_nextPulseAt
- protected PortableQueue<PortableMessageRef>
_outgoingMessages
Friend methods: