PhoenixZMQ  8.1.3
Library which integrates zeromq use
Loading...
Searching...
No Matches
phoenix_zmq.cpp File Reference
#include <sstream>
#include "phoenix_zmq.h"
+ Include dependency graph for phoenix_zmq.cpp:

Go to the source code of this file.

Functions

void pzmq_closeServerSocket (zmq::socket_t *&socket)
 Close the given server socket.
 
zmq::socket_t * pzmq_createClientSocket (zmq::context_t &context, const std::string &address, size_t port, int type, int nbBufferMessage, int bufferSizeByte, size_t threadAffinity, ssize_t dataRate, int immediate)
 Add a client socket to the manager.
 
zmq::socket_t * pzmq_createClientSocket (zmq::context_t &context, int type, const std::string &address, size_t port, int immediate)
 Create a client socket to be used by the SocketManagerZMQ.
 
zmq::socket_t * pzmq_createServerSocket (zmq::context_t &context, int type, size_t port)
 Create a server socket to be used by the SocketManagerZMQ.
 
zmq::socket_t * pzmq_createServerSocket (zmq::context_t &context, size_t port, int type, int nbBufferMessage, int bufferSizeByte, size_t threadAffinity, ssize_t dataRate)
 Add a server socket to the manager.
 
void pzmq_setBufferSize (zmq::socket_t *socket, int type, int nbBufferMessage, int dataRate, size_t bufferSizeByte)
 Set the size of the buffer to send messages.
 
void pzmq_setDataRate (zmq::socket_t *socket, int type, int dataRate)
 Set the data rate of the socket.
 
void pzmq_setNbMessageBuffer (zmq::socket_t *socket, int nbBufferMessage)
 Set the number of messages in the messages buffer.
 
void pzmq_setRecvBufferSize (zmq::socket_t *socket, int bufferSizeByte)
 Set the size of the buffer to received messages.
 
void pzmq_setSendBufferSize (zmq::socket_t *socket, int bufferSizeByte)
 Set the size of the buffer to send messages.
 
void pzmq_setThreadAffinity (zmq::socket_t *socket, size_t threadAffinity)
 Set the thread affinity of zmq.
 

Function Documentation

◆ pzmq_closeServerSocket()

void pzmq_closeServerSocket ( zmq::socket_t *& socket)

Close the given server socket.

Parameters
[out]socket: pointer to the server socket to be closed (will be set to NULL at then end of the function)

Definition at line 117 of file phoenix_zmq.cpp.

117 {
118 if(socket != NULL){
119 socket->close();
120 delete socket;
121 socket = NULL;
122 }
123}

◆ pzmq_createClientSocket() [1/2]

zmq::socket_t * pzmq_createClientSocket ( zmq::context_t & context,
const std::string & address,
size_t port,
int type,
int nbBufferMessage,
int bufferSizeByte,
size_t threadAffinity,
ssize_t dataRate,
int immediate )

Add a client socket to the manager.

Parameters
context: zmq context where to create socket
address: address of the server to be connected to
port: port to be used
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
zmq socket

Definition at line 101 of file phoenix_zmq.cpp.

103{
104 zmq::socket_t* socket = pzmq_createClientSocket(context, type, address, port, immediate);
105 bool b(socket != NULL);
106 if(b){
107 pzmq_setBufferSize(socket, type, nbBufferMessage, dataRate, bufferSizeByte);
108 pzmq_setThreadAffinity(socket, threadAffinity);
109 }
110 return socket;
111}
zmq::socket_t * pzmq_createClientSocket(zmq::context_t &context, int type, const std::string &address, size_t port, int immediate)
Create a client socket to be used by the SocketManagerZMQ.
void pzmq_setThreadAffinity(zmq::socket_t *socket, size_t threadAffinity)
Set the thread affinity of zmq.
void pzmq_setBufferSize(zmq::socket_t *socket, int type, int nbBufferMessage, int dataRate, size_t bufferSizeByte)
Set the size of the buffer to send messages.

References pzmq_createClientSocket(), pzmq_setBufferSize(), and pzmq_setThreadAffinity().

+ Here is the call graph for this function:

◆ pzmq_createClientSocket() [2/2]

zmq::socket_t * pzmq_createClientSocket ( zmq::context_t & context,
int type,
const std::string & address,
size_t port,
int immediate )

Create a client socket to be used by the SocketManagerZMQ.

Parameters
context: zeromq context which defines the number of thread to be used in the data transfert
type: type of the socket (ZMQ_PULL, ZMQ_PUSH, etc)
address: address of the socket (example localhost or 127.0.0.1)
port: port to be used
Returns
create socket

Definition at line 18 of file phoenix_zmq.cpp.

18 {
19 std::stringstream socketAddressData;
20 socketAddressData << "tcp://" << address <<":" << port;
21 zmq::socket_t *socket = new zmq::socket_t(context, type);
22 if(socket == NULL){return NULL;}
23
24#if (CPPZMQ_VERSION_MAJOR*100 + CPPZMQ_VERSION_MINOR*10 + CPPZMQ_VERSION_PATCH) >= 471
25 socket->set(zmq::sockopt::immediate, immediate);
26 socket->set(zmq::sockopt::linger, -1); //1 ms to stop
27#else
28 int immediateVal(immediate);
29 socket->setsockopt(ZMQ_IMMEDIATE, &immediateVal, sizeof(int));
30 socket->setsockopt(ZMQ_LINGER, -1); //1 ms to stop
31#endif
32 socket->connect(socketAddressData.str()); // ← connect APRÈS les options
33
34 if(type == ZMQ_SUB){
35#if (CPPZMQ_VERSION_MAJOR*100 + CPPZMQ_VERSION_MINOR*10 + CPPZMQ_VERSION_PATCH) >= 471
36 socket->set(zmq::sockopt::subscribe, "");
37 socket->set(zmq::sockopt::conflate, 1);
38#else
39 socket->setsockopt(ZMQ_SUBSCRIBE, "", 0);
40 int conflate(1);
41 socket->setsockopt(ZMQ_CONFLATE, &conflate, sizeof(int));
42#endif
43 }
44 return socket;
45}

Referenced by PZmqSocket::createClientSocket(), and pzmq_createClientSocket().

+ Here is the caller graph for this function:

◆ pzmq_createServerSocket() [1/2]

zmq::socket_t * pzmq_createServerSocket ( zmq::context_t & context,
int type,
size_t port )

Create a server socket to be used by the SocketManagerZMQ.

Parameters
context: zeromq context which defines the number of thread to be used in the data transfert
type: type of the socket (ZMQ_PULL, ZMQ_PUSH, etc)
port: port to be used
Returns
create socket

Definition at line 52 of file phoenix_zmq.cpp.

52 {
53 std::stringstream socketAddressData;
54 socketAddressData << "tcp://127.0.0.1:" << port;
55 zmq::socket_t *socket = new zmq::socket_t(context, type);
56 if(socket != NULL){
57 socket->bind(socketAddressData.str());
58#if (CPPZMQ_VERSION_MAJOR*100 + CPPZMQ_VERSION_MINOR*10 + CPPZMQ_VERSION_PATCH) >= 471
59 socket->set(zmq::sockopt::linger, -1); //1 ms to stop
60#else
61 socket->setsockopt(ZMQ_LINGER, -1); //1 ms to stop
62#endif
63 }
64 return socket;
65}

Referenced by PZmqSocket::createServerSocket(), and pzmq_createServerSocket().

+ Here is the caller graph for this function:

◆ pzmq_createServerSocket() [2/2]

zmq::socket_t * pzmq_createServerSocket ( zmq::context_t & context,
size_t port,
int type,
int nbBufferMessage,
int bufferSizeByte,
size_t threadAffinity,
ssize_t dataRate )

Add a server socket to the manager.

Parameters
context: zmq context where to create socket
port: port to be used
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
zmq socket

Definition at line 77 of file phoenix_zmq.cpp.

79{
80 zmq::socket_t* socket = pzmq_createServerSocket(context, type, port);
81 bool b(socket != NULL);
82 if(b){
83 pzmq_setBufferSize(socket, type, nbBufferMessage, dataRate, bufferSizeByte);
84 pzmq_setThreadAffinity(socket, threadAffinity);
85 }
86 return socket;
87}
zmq::socket_t * pzmq_createServerSocket(zmq::context_t &context, int type, size_t port)
Create a server socket to be used by the SocketManagerZMQ.

References pzmq_createServerSocket(), pzmq_setBufferSize(), and pzmq_setThreadAffinity().

+ Here is the call graph for this function:

◆ pzmq_setBufferSize()

void pzmq_setBufferSize ( zmq::socket_t * socket,
int type,
int nbBufferMessage,
int dataRate,
size_t bufferSizeByte )

Set the size of the buffer to send messages.

Parameters
[out]socket: socket to be modified
type: type of the socket to be used
nbBufferMessage: number of messages to be buffered
dataRate: expected data rate (in kilobytes per second)
bufferSizeByte: size of the zmq buffer in bytes

Definition at line 210 of file phoenix_zmq.cpp.

210 {
211 pzmq_setNbMessageBuffer(socket, nbBufferMessage);
212 pzmq_setDataRate(socket, type, dataRate);
213 if(type == ZMQ_PULL || type == ZMQ_SUB){
214 pzmq_setRecvBufferSize(socket, bufferSizeByte);
215 }else if(type == ZMQ_PUSH || type == ZMQ_PUB){
216 pzmq_setSendBufferSize(socket, bufferSizeByte);
217 }
218}
void pzmq_setSendBufferSize(zmq::socket_t *socket, int bufferSizeByte)
Set the size of the buffer to send messages.
void pzmq_setRecvBufferSize(zmq::socket_t *socket, int bufferSizeByte)
Set the size of the buffer to received messages.
void pzmq_setDataRate(zmq::socket_t *socket, int type, int dataRate)
Set the data rate of the socket.
void pzmq_setNbMessageBuffer(zmq::socket_t *socket, int nbBufferMessage)
Set the number of messages in the messages buffer.

References pzmq_setDataRate(), pzmq_setNbMessageBuffer(), pzmq_setRecvBufferSize(), and pzmq_setSendBufferSize().

Referenced by pzmq_createClientSocket(), and pzmq_createServerSocket().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pzmq_setDataRate()

void pzmq_setDataRate ( zmq::socket_t * socket,
int type,
int dataRate )

Set the data rate of the socket.

Parameters
[out]socket: socket to be modified
type: type of the socket to be used
dataRate: expected data rate (in kilobytes per second)

Definition at line 146 of file phoenix_zmq.cpp.

146 {
147 if(socket != NULL && (type == ZMQ_PUB || type == ZMQ_SUB)){
148 int dataRateKbit(dataRate*8l);
149#if (CPPZMQ_VERSION_MAJOR*100 + CPPZMQ_VERSION_MINOR*10 + CPPZMQ_VERSION_PATCH) >= 471
150 socket->set(zmq::sockopt::rate, dataRateKbit);
151#else
152 //See doc at http://api.zeromq.org/3-1:zmq-setsockopt
153 socket->setsockopt(ZMQ_RATE, dataRateKbit);
154#endif
155 }
156}

Referenced by pzmq_setBufferSize().

+ Here is the caller graph for this function:

◆ pzmq_setNbMessageBuffer()

void pzmq_setNbMessageBuffer ( zmq::socket_t * socket,
int nbBufferMessage )

Set the number of messages in the messages buffer.

Parameters
[out]socket: socket to be modified
nbBufferMessage: number of messages to be buffered

Definition at line 129 of file phoenix_zmq.cpp.

129 {
130 if(socket != NULL){
131#if (CPPZMQ_VERSION_MAJOR*100 + CPPZMQ_VERSION_MINOR*10 + CPPZMQ_VERSION_PATCH) >= 471
132 socket->set(zmq::sockopt::rcvhwm, nbBufferMessage);
133#else
134 //See doc at http://api.zeromq.org/3-1:zmq-setsockopt
135 socket->setsockopt(ZMQ_RCVHWM, &nbBufferMessage, sizeof(int));
136 socket->setsockopt(ZMQ_SNDHWM, &nbBufferMessage, sizeof(int));
137#endif
138 }
139}

Referenced by pzmq_setBufferSize().

+ Here is the caller graph for this function:

◆ pzmq_setRecvBufferSize()

void pzmq_setRecvBufferSize ( zmq::socket_t * socket,
int bufferSizeByte )

Set the size of the buffer to received messages.

Parameters
[out]socket: socket to be modified
bufferSizeByte: size of the zmq buffer in bytes

Definition at line 162 of file phoenix_zmq.cpp.

162 {
163 if(socket != NULL){
164#if (CPPZMQ_VERSION_MAJOR*100 + CPPZMQ_VERSION_MINOR*10 + CPPZMQ_VERSION_PATCH) >= 471
165 socket->set(zmq::sockopt::rcvbuf, bufferSizeByte);
166#else
167 //See doc at http://api.zeromq.org/3-1:zmq-setsockopt
168 socket->setsockopt(ZMQ_RCVBUF, bufferSizeByte);
169#endif
170 }
171}

Referenced by pzmq_setBufferSize().

+ Here is the caller graph for this function:

◆ pzmq_setSendBufferSize()

void pzmq_setSendBufferSize ( zmq::socket_t * socket,
int bufferSizeByte )

Set the size of the buffer to send messages.

Parameters
[out]socket: socket to be modified
bufferSizeByte: size of the zmq buffer in bytes

Definition at line 177 of file phoenix_zmq.cpp.

177 {
178 if(socket != NULL){
179#if (CPPZMQ_VERSION_MAJOR*100 + CPPZMQ_VERSION_MINOR*10 + CPPZMQ_VERSION_PATCH) >= 471
180 socket->set(zmq::sockopt::sndbuf, bufferSizeByte);
181#else
182 //See doc at http://api.zeromq.org/3-1:zmq-setsockopt
183 socket->setsockopt(ZMQ_SNDBUF, bufferSizeByte);
184#endif
185 }
186}

Referenced by pzmq_setBufferSize().

+ Here is the caller graph for this function:

◆ pzmq_setThreadAffinity()

void pzmq_setThreadAffinity ( zmq::socket_t * socket,
size_t threadAffinity )

Set the thread affinity of zmq.

Parameters
socket: socket to be modified
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)

Definition at line 192 of file phoenix_zmq.cpp.

192 {
193 if(socket != NULL){
194#if (CPPZMQ_VERSION_MAJOR*100 + CPPZMQ_VERSION_MINOR*10 + CPPZMQ_VERSION_PATCH) >= 471
195 socket->set(zmq::sockopt::affinity, threadAffinity);
196#else
197 //See doc at http://api.zeromq.org/3-1:zmq-setsockopt
198 socket->setsockopt(ZMQ_AFFINITY, threadAffinity);
199#endif
200 }
201}

Referenced by pzmq_createClientSocket(), and pzmq_createServerSocket().

+ Here is the caller graph for this function: