|
AndroMeta
2.0.0
|
A network communication class for sending and receiving MVar's asynchronously. More...
#include <MCommunicator.h>
Public Member Functions | |
| MCommunicator (MProcTask *task, MMessageBuffer *sendBuffer=0, MMessageBuffer *receiveBuffer=0) | |
| virtual | ~MCommunicator () |
| MProcTask * | task () |
| MMessageBuffer * | sendBuffer () |
| MMessageBuffer * | receiveBuffer () |
| void | close (bool manual=true) |
| virtual void | onClose (bool manual) |
| virtual void | onConnect () |
| bool | isConnected () const |
| bool | send (MMessage *msg) |
| bool | send (const mvar &header, const mvar &body) |
| bool | send (const mvar &body) |
| bool | receive (mvar &header, mvar &body) |
| bool | receive (mvar &body) |
| bool | receive (mvar &header, mvar &body, const mtime &timeout) |
| bool | receive (mvar &body, const mtime &timeout) |
A network communication class for sending and receiving MVar's asynchronously.
MCommunicator provides and easy-to-use interface for communicating (complex) data over a socket. MVar's may be sent and received asynchronously. Internally, mvar's are sent and received in compressed binary form.
| Meta::MCommunicator::MCommunicator | ( | MProcTask * | task, |
| MMessageBuffer * | sendBuffer = 0, |
||
| MMessageBuffer * | receiveBuffer = 0 |
||
| ) |
Constructor.
| task | The task to use for concurrent/communications processing. |
| sendBuffer | The message buffer to be used for sending. Messages placed in the send buffer are queued for sending using the normal message buffer and message handling semantics. If null, then a send buffer is created and managed internally. |
| receiveBuffer | The message buffer to be used for receiving messages. Received messages are placed in the receive buffer and a message handler is used internally for receiving messages however external message handlers may also respond to messages in this buffer in the usual way. If null, then a receive buffer is created and managed internally. |
| virtual Meta::MCommunicator::~MCommunicator | ( | ) | [virtual] |
Destructor.
| void Meta::MCommunicator::close | ( | bool | manual = true | ) | [virtual] |
Shutdown and close the communicator.
| manual | True if the communicator is closing manually as opposed to being closed at the socket-level. |
Reimplemented from Meta::MSocket.
| bool Meta::MCommunicator::isConnected | ( | ) | const |
| virtual void Meta::MCommunicator::onClose | ( | bool | manual | ) | [virtual] |
Called when the communicator is closed.
| manual | Indicates that the communicator was closed manually as opposed to being closed at the socket-level. |
| virtual void Meta::MCommunicator::onConnect | ( | ) | [virtual] |
Called upon successful connect. When re-implementing, MCommunicator::onConnect() must be called.
Reimplemented from Meta::MSocket.
| bool Meta::MCommunicator::receive | ( | mvar & | header, |
| mvar & | body | ||
| ) |
Block until the next message is received by the communicator, retrieving header and body.
| bool Meta::MCommunicator::receive | ( | mvar & | body | ) |
Block until the next message is received by the communicator, retrieving body.
| bool Meta::MCommunicator::receive | ( | mvar & | header, |
| mvar & | body, | ||
| const mtime & | timeout | ||
| ) |
Block until the next message is received by the communicator or call times out, retrieving header and body.
| bool Meta::MCommunicator::receive | ( | mvar & | body, |
| const mtime & | timeout | ||
| ) |
Block until the next message is received by the communicator or call times out, retrieving body.
| bool Meta::MCommunicator::send | ( | MMessage * | msg | ) |
The fastest way to send a message as the message data is supplied directly as a pointer. Sends asynchronously.
| msg | The message to send -- consumed by communicator so it should not be deleted after this call. |
| bool Meta::MCommunicator::send | ( | const mvar & | header, |
| const mvar & | body | ||
| ) |
Convenience method to asynchronously send a message by passing header and body.
| bool Meta::MCommunicator::send | ( | const mvar & | body | ) |
Convenience method to asynchronously send a message without a header. This is the most common usage.
1.7.6.1