PhoenixZMQ  7.2.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, int linger)
 Create param for a client socket.
 
PZmqParam pzmq_createParamServer (int type, int nbBufferMessage, int bufferSizeByte, size_t threadAffinity, ssize_t dataRate, int linger)
 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 43 of file PZmqBackend.cpp.

43 {
44 if(res.has_value()){
45 return PRecvStatus::OK;
46 }else{
47 int err = zmq_errno();
48 if(err == EAGAIN){
49 return PRecvStatus::NO_MESSAGE_RECEIVED;
50 }else{
51 return PRecvStatus::BROKEN_SOCKET;
52 }
53 }
54}

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 }else{
24 int err = zmq_errno();
25 if(err == EAGAIN){
26 return PSendStatus::SOCKET_NOT_AVAILABLE;
27 }else{
28 std::cerr << "Unknown ZMQ error in send: '" << err << "'"<< std::endl;
29 return PSendStatus::BROKEN_BACKEND;
30 }
31 }
32}

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 69 of file PZmqBackend.cpp.

69 {
70 if(flag == PRecvFlag::NON_BLOCK){return zmq::recv_flags::dontwait;}
71 else{return zmq::recv_flags::none;}
72}

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 60 of file PZmqBackend.cpp.

60 {
61 if(flag == PSendFlag::NON_BLOCK){return zmq::send_flags::dontwait;}
62 else{return zmq::send_flags::none;}
63}

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,
int linger )

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)
linger: linger period for socket shutdown
Returns
corresponding PZmqParam

Definition at line 84 of file PZmqBackend.cpp.

84 {
85 PZmqParam param;
86 param.type = type;
87 param.nbBufferMessage = nbBufferMessage;
88 param.bufferSizeByte = bufferSizeByte;
89 param.threadAffinity = threadAffinity;
90 param.dataRate = dataRate;
91 param.linger = linger;
92 return param;
93}
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
int linger
linger period for socket shutdown
Definition PZmqBackend.h:29
size_t threadAffinity
Mask of threads which deal with reconnection.
Definition PZmqBackend.h:25

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

Referenced by PZmqSocketGenerator::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,
int linger )

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)
linger: linger period for socket shutdown
Returns
corresponding PZmqParam

Definition at line 104 of file PZmqBackend.cpp.

104 {
105 PZmqParam param;
106 param.type = type;
107 param.nbBufferMessage = nbBufferMessage;
108 param.bufferSizeByte = bufferSizeByte;
109 param.threadAffinity = threadAffinity;
110 param.dataRate = dataRate;
111 param.linger = linger;
112 return param;
113}

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

Referenced by PZmqSocketGenerator::server().

+ Here is the caller graph for this function: