PhoenixZMQ  6.0.0
Library which integrates zeromq use
Loading...
Searching...
No Matches
PZmqBackend.h File Reference
#include <string>
#include "PSocketFlag.h"
#include "phoenix_generic_mock.h"
#include "phoenix_data_stream.h"
#include "phoenix_zmq.h"
#include "PZmqBackend_impl.h"
+ Include dependency graph for PZmqBackend.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  PZmqBackend
 Backend to use Mock library with PAbtractSocket. More...
 
struct  PZmqParam
 Set of parameters to be passed to create a socket with zmq backend. More...
 
class  PZmqSocket
 PhoenixSocket API bridge to ZMQ socket. More...
 

Functions

PRecvStatus::PRecvStatus checkRecvStatus (zmq::recv_result_t res)
 Check the recv result and convert it into PRecvStatus.
 
PSendStatus::PSendStatus checkSendStatus (zmq::send_result_t res)
 Check the send result and convert it into PSendStatus.
 
PZmqParam pzmq_createParamClient (int type, int nbBufferMessage=10000, int bufferSizeByte=1000000, size_t threadAffinity=0lu, ssize_t dataRate=200000l)
 Create param for a client socket.
 
PZmqParam pzmq_createParamServer (int type, int nbBufferMessage=10000, int bufferSizeByte=1000000, size_t threadAffinity=0lu, ssize_t dataRate=200000l)
 Create param for a client socket.
 
template<typename T>
std::string statusToStr (T status)
 Convert PSendStatus into string.
 

Function Documentation

◆ checkRecvStatus()

PRecvStatus::PRecvStatus checkRecvStatus ( zmq::recv_result_t res)

Check the recv result and convert it into PRecvStatus.

Parameters
res: result of the zmq recv
Returns
corresponding PRecvStatus

ZMQ socket recv has a bit of a strange implementation:

  • if recv works: the recv_result_t has a value
  • if recv doesn't work due to EAGAIN error: the recv_result_t is empty (no value) and error should be EAGAIN
  • if recv doesn't work for another reason: an exception is thrown This function only checks the behaviour due to the recv result, not the thrown error.

Definition at line 46 of file PZmqBackend.cpp.

46 {
47 if(res.has_value()){
48 return PRecvStatus::OK;
49 }
50 else{
51 int err = zmq_errno();
52 if(err == EAGAIN){
53 return PRecvStatus::NO_MESSAGE_RECEIVED;
54 }
55 else{
56 return PRecvStatus::BROKEN_SOCKET;
57 }
58 }
59}

Referenced by PZmqSocket::recvMsg().

+ Here is the caller graph for this function:

◆ checkSendStatus()

PSendStatus::PSendStatus checkSendStatus ( zmq::send_result_t res)

Check the send result and convert it into PSendStatus.

Parameters
res: result of the zmq send
Returns
corresponding PSendStatus

ZMQ socket send has a bit of a strange implementation:

  • if sending works: the send_result_t has a value
  • if sending doesn't work due to EAGAIN error: the send_result_t is empty (no value) and error should be EAGAIN
  • if sending doesn't work for another reason: an exception is thrown This function only checks the behaviour due to the send result, not the thrown error.

Definition at line 20 of file PZmqBackend.cpp.

20 {
21 if(res.has_value()){
22 return PSendStatus::OK;
23 }
24 else{
25 int err = zmq_errno();
26 if(err == EAGAIN){
27 return PSendStatus::SOCKET_NOT_AVAILABLE;
28 }
29 else{
30 std::cerr << "Unknown ZMQ error in send: '" << err << "'"<< std::endl;
31 return PSendStatus::BROKEN_BACKEND;
32 }
33 }
34}

Referenced by PZmqSocket::sendMsg().

+ Here is the caller graph for this function:

◆ pzmq_createParamClient()

PZmqParam pzmq_createParamClient ( int type,
int nbBufferMessage,
int bufferSizeByte,
size_t threadAffinity,
ssize_t dataRate )

Create param for a client socket.

Parameters
context: zmq context where to create socket
type: type of the connection (ZMQ_PULL, ZMQ_PUSH, etc)
nbBufferMessage: number of messages to be buffered
bufferSizeByte: size of the zmq buffer in bytes
threadAffinity: bit mask which determines which threads from the 0MQ I/O thread pool associated with the socket's context shall handle newly created connections (1 : means first, 2 : means second, 3 : means first and second, etc)
dataRate: expected data rate (in kilobytes per second)
Returns
corresponding PZmqParam

Definition at line 88 of file PZmqBackend.cpp.

90{
91 PZmqParam param;
92 param.type = type;
93 param.nbBufferMessage = nbBufferMessage;
94 param.bufferSizeByte = bufferSizeByte;
95 param.threadAffinity = threadAffinity;
96 param.dataRate = dataRate;
97 return param;
98}
Set of parameters to be passed to create a socket with zmq backend.
Definition PZmqBackend.h:17
ssize_t dataRate
Data rate.
Definition PZmqBackend.h:27
int nbBufferMessage
Number of messages in the buffer.
Definition PZmqBackend.h:21
int bufferSizeByte
Size of the message buffer in bytes.
Definition PZmqBackend.h:23
int type
Socket type.
Definition PZmqBackend.h:19
size_t threadAffinity
Mask of threads which deal with reconnection.
Definition PZmqBackend.h:25

References PZmqParam::bufferSizeByte, PZmqParam::dataRate, PZmqParam::nbBufferMessage, PZmqParam::threadAffinity, and PZmqParam::type.

Referenced by PZmqBackend::client().

+ Here is the caller graph for this function:

◆ pzmq_createParamServer()

PZmqParam pzmq_createParamServer ( int type,
int nbBufferMessage,
int bufferSizeByte,
size_t threadAffinity,
ssize_t dataRate )

Create param for a client socket.

Parameters
type: type of the connection (ZMQ_PULL, ZMQ_PUSH, etc)
nbBufferMessage: number of messages to be buffered
bufferSizeByte: size of the zmq buffer in bytes
threadAffinity: bit mask which determines which threads from the 0MQ I/O thread pool associated with the socket's context shall handle newly created connections (1 : means first, 2 : means second, 3 : means first and second, etc)
dataRate: expected data rate (in kilobytes per second)
Returns
corresponding PZmqParam

Definition at line 108 of file PZmqBackend.cpp.

110{
111 PZmqParam param;
112 param.type = type;
113 param.nbBufferMessage = nbBufferMessage;
114 param.bufferSizeByte = bufferSizeByte;
115 param.threadAffinity = threadAffinity;
116 param.dataRate = dataRate;
117 return param;
118}

References PZmqParam::bufferSizeByte, PZmqParam::dataRate, PZmqParam::nbBufferMessage, PZmqParam::threadAffinity, and PZmqParam::type.

Referenced by PZmqBackend::server().

+ Here is the caller graph for this function:

◆ statusToStr()

template<typename T>
std::string statusToStr ( T status)

Convert PSendStatus into string.

Parameters
status: PSendStatus to be converted
Returns
corresponding string

Definition at line 19 of file PZmqBackend_impl.h.

19 {
20 if constexpr (std::is_same_v<T, PSendStatus::PSendStatus>) {
21 switch (status) {
22 case PSendStatus::OK: return "OK";
23 case PSendStatus::SOCKET_NOT_AVAILABLE: return "SOCKET_NOT_AVAILABLE";
24 case PSendStatus::NO_ROUTE_TO_RECEIVER: return "NO_ROUTE_TO_RECEIVER";
25 case PSendStatus::SIGNAL_INTERRUPTION: return "SIGNAL_INTERRUPTION";
26 case PSendStatus::BROKEN_BACKEND: return "BROKEN_BACKEND";
27 case PSendStatus::BROKEN_SOCKET: return "BROKEN_SOCKET";
28 case PSendStatus::CANNOT_SERIALIZE_DATA: return "CANNOT_SERIALIZE_DATA";
29 default: return "UNKNOWN_SEND_STATUS";
30 }
31 } else if constexpr (std::is_same_v<T, PRecvStatus::PRecvStatus>) {
32 switch (status) {
33 case PRecvStatus::OK: return "OK";
34 case PRecvStatus::SOCKET_NOT_AVAILABLE: return "SOCKET_NOT_AVAILABLE";
35 case PRecvStatus::SIGNAL_INTERRUPTION: return "SIGNAL_INTERRUPTION";
36 case PRecvStatus::BROKEN_BACKEND: return "BROKEN_BACKEND";
37 case PRecvStatus::BROKEN_SOCKET: return "BROKEN_SOCKET";
38 case PRecvStatus::NO_MESSAGE_RECEIVED: return "NO_MESSAGE_RECEIVED";
39 case PRecvStatus::CANNOT_DESERIALIZE_DATA: return "CANNOT_DESERIALIZE_DATA";
40 default: return "UNKNOWN_RECV_STATUS";
41 }
42 } else {
43 return "UNKNOWN_STATUS_TYPE";
44 }
45}