#include <CZMQTransport.h> class CZMQTransport : public CTransport { public: CZMQTransport(); void recv(void** ppData, size_t& size); void send(iovec* parts, size_t numParts); void end(); static zmq::context_t* getContext(); operator zmq::socket_t*(); protected: void setSocket(zmq::socket_t* pSocket); }; */ class CZMQRawTransport : public CZMQTransport { public: CZMQRawTransport(zmq::socket_t* sock); };
These two classes encapsulate ZeroMQ sockets.
CZMQTransport
is intended
to be used as a base class for more interesting
transports using ZeroMQ.
CZMQRawTransport
, on the other
hand, wraps a raw ZeroMQ
zmq::socket_t
in a transport.
This class is not useful in and of itself.
The intent is that it be a base class and the
resulting concrete class sets up the
appropriate zmq::socket_t
and wraps it using the
setSocket
method
described below.
CZMQTransport();
This constructor does not supply
a socket on which to transport
data. To create a useful class,
the programmer must derive a class from
this whose constructor sets up a socket and
wraps the base class around it by calling
setSocket
below.
void recv(void** ppData, size_t& size);
Receives data on the underlying socket. If the message is a multipart message, all the parts are concatenated into a single block and that block is returned. If you wish to retain message part boundaries you need to define a higher level data format that an do that.
void send(iovec* parts, size_t numParts);
Sends a message on the underlying socket.
Note that each element of the
parts
array is
sent as a separate message part
(zmq::message_t
object).
void end();
Sends a message consisting of a single message part with a length of zero. That's a flag that the receiver should not expect any more data.
static zmq::context_t* getContext();
Provides a factory message to get a singleton ZMQ context object. A pointer to the application unique context is returned. This context is created on the first call to this method and must not be deleted by the application.
zmq::socket_t* operator zmq::socket_t*();();
Conversion operator that allows the object to be treated as it's underlying socket_t for special applications.
protected void setSocket(zmq::socket_t* pSocket);
Intended to be called by derived classes. This method sets the socket on which communication will take place.