lcls2
C++ API: public headers of xtcdata, psalg, psdaq and psana
Loading...
Searching...
No Matches
ZmqSocket Class Reference

Wraps one ZeroMQ socket created from a ZmqContext. More...

#include <Collection.hh>

Public Member Functions

 ZmqSocket (ZmqContext *context, int type)
 Create a socket of the given ZeroMQ type in context.
 
 ~ZmqSocket ()
 Close the socket.
 
void connect (const std::string &host)
 Connect the socket to the endpoint host; throws std::runtime_error on failure.
 
void bind (const std::string &host)
 Bind the socket to the endpoint host; throws std::runtime_error on failure.
 
void setsockopt (int option, const void *optval, size_t optvallen)
 Set a socket option; throws std::runtime_error on failure.
 
std::string recv ()
 Receive one frame and return it as a string; logs an error and returns an empty string if the receive fails.
 
nlohmann::json recvJson ()
 Receive one frame and parse it as JSON; logs an error and returns an empty JSON object if the receive fails.
 
std::vector< ZmqMessage > recvMultipart ()
 Receive all frames of one multi-part message; returns an empty vector (after logging) if a receive or ZMQ_RCVMORE query fails.
 
void send (const std::string &msg)
 Send msg as one frame; a failure is only logged.
 
int poll (short events, long timeout)
 Poll this socket for events for up to timeout (zmq_poll() units) and return the zmq_poll() result.
 

Public Attributes

void * socket
 Raw ZeroMQ socket handle.
 

Detailed Description

Wraps one ZeroMQ socket created from a ZmqContext.

Constructor & Destructor Documentation

◆ ZmqSocket()

ZmqSocket::ZmqSocket ( ZmqContext *  context,
int  type 
)

Create a socket of the given ZeroMQ type in context.

◆ ~ZmqSocket()

ZmqSocket::~ZmqSocket ( )
inline

Close the socket.

Member Function Documentation

◆ bind()

void ZmqSocket::bind ( const std::string &  host)

Bind the socket to the endpoint host; throws std::runtime_error on failure.

◆ connect()

void ZmqSocket::connect ( const std::string &  host)

Connect the socket to the endpoint host; throws std::runtime_error on failure.

◆ poll()

int ZmqSocket::poll ( short  events,
long  timeout 
)

Poll this socket for events for up to timeout (zmq_poll() units) and return the zmq_poll() result.

◆ recv()

std::string ZmqSocket::recv ( )

Receive one frame and return it as a string; logs an error and returns an empty string if the receive fails.

◆ recvJson()

nlohmann::json ZmqSocket::recvJson ( )

Receive one frame and parse it as JSON; logs an error and returns an empty JSON object if the receive fails.

◆ recvMultipart()

std::vector< ZmqMessage > ZmqSocket::recvMultipart ( )

Receive all frames of one multi-part message; returns an empty vector (after logging) if a receive or ZMQ_RCVMORE query fails.

◆ send()

void ZmqSocket::send ( const std::string &  msg)

Send msg as one frame; a failure is only logged.

◆ setsockopt()

void ZmqSocket::setsockopt ( int  option,
const void *  optval,
size_t  optvallen 
)

Set a socket option; throws std::runtime_error on failure.

Member Data Documentation

◆ socket

void* ZmqSocket::socket

Raw ZeroMQ socket handle.


The documentation for this class was generated from the following file: