PhoenixZMQ  6.0.0
Library which integrates zeromq use
Loading...
Searching...
No Matches
PZmqBackend.cpp File Reference
#include "PZmqBackend.h"
+ Include dependency graph for PZmqBackend.cpp:

Go to the source code of this file.

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.
 
zmq::recv_flags convertToRecvFlag (PRecvFlag::PRecvFlag flag)
 Convert a recv flag into zmq flag.
 
zmq::send_flags convertToSendFlag (PSendFlag::PSendFlag flag)
 Convert a send flag into zmq flag.
 
PZmqParam pzmq_createParamClient (int type, int nbBufferMessage, int bufferSizeByte, size_t threadAffinity, ssize_t dataRate)
 Create param for a client socket.
 
PZmqParam pzmq_createParamServer (int type, int nbBufferMessage, int bufferSizeByte, size_t threadAffinity, ssize_t dataRate)
 Create param for a client socket.
 

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:

◆ convertToRecvFlag()

zmq::recv_flags convertToRecvFlag ( PRecvFlag::PRecvFlag flag)

Convert a recv flag into zmq flag.

Parameters
flag: generic PRecvFlag
Returns
corresponding zmq::recv_flags

Definition at line 74 of file PZmqBackend.cpp.

74 {
75 if(flag == PRecvFlag::NON_BLOCK){return zmq::recv_flags::dontwait;}
76 else{return zmq::recv_flags::none;}
77}

Referenced by PZmqSocket::recvMsg().

+ Here is the caller graph for this function:

◆ convertToSendFlag()

zmq::send_flags convertToSendFlag ( PSendFlag::PSendFlag flag)

Convert a send flag into zmq flag.

Parameters
flag: generic PSendFlag
Returns
corresponding zmq::send_flags

Definition at line 65 of file PZmqBackend.cpp.

65 {
66 if(flag == PSendFlag::NON_BLOCK){return zmq::send_flags::dontwait;}
67 else{return zmq::send_flags::none;}
68}

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: