1212
1313using namespace sairedis ;
1414
15- #define ZMQ_RESPONSE_BUFFER_SIZE (64 *1024 *1024 )
1615#define ZMQ_MAX_RETRY 10
1716
1817ZeroMQChannel::ZeroMQChannel (
1918 _In_ const std::string& endpoint,
2019 _In_ const std::string& ntfEndpoint,
21- _In_ Channel::Callback callback):
20+ _In_ Channel::Callback callback,
21+ _In_ long zmqResponseBufferSize):
2222 Channel(callback),
2323 m_endpoint(endpoint),
2424 m_ntfEndpoint(ntfEndpoint),
2525 m_context(nullptr ),
2626 m_socket(nullptr ),
2727 m_ntfContext(nullptr ),
28- m_ntfSocket(nullptr )
28+ m_ntfSocket(nullptr ),
29+ m_zmqResponseBufferSize(zmqResponseBufferSize)
2930{
3031 SWSS_LOG_ENTER ();
32+ if (m_zmqResponseBufferSize != ZMQ_RESPONSE_DEFAULT_BUFFER_SIZE)
33+ {
34+ SWSS_LOG_NOTICE (" setting zmq response buffer size to %ld bytes" , m_zmqResponseBufferSize);
35+ }
36+ else
37+ {
38+ SWSS_LOG_NOTICE (" using default zmq response buffer size of %ld bytes" , ZMQ_RESPONSE_DEFAULT_BUFFER_SIZE);
39+ }
3140
32- m_buffer.resize (ZMQ_RESPONSE_BUFFER_SIZE );
41+ m_buffer.resize (m_zmqResponseBufferSize );
3342
3443 // configure ZMQ for main communication
3544
@@ -129,14 +138,14 @@ void ZeroMQChannel::notificationThreadFunction()
129138
130139 std::vector<uint8_t > buffer;
131140
132- buffer.resize (ZMQ_RESPONSE_BUFFER_SIZE );
141+ buffer.resize (m_zmqResponseBufferSize );
133142
134143 while (m_runNotificationThread)
135144 {
136145 // NOTE: this entire loop internal could be encapsulated into separate class
137146 // which will inherit from Selectable class, and name this as ntf receiver
138147
139- int rc = zmq_recv (m_ntfSocket, buffer.data (), ZMQ_RESPONSE_BUFFER_SIZE , 0 );
148+ int rc = zmq_recv (m_ntfSocket, buffer.data (), m_zmqResponseBufferSize , 0 );
140149
141150 if (!m_runNotificationThread)
142151 break ;
@@ -156,10 +165,10 @@ void ZeroMQChannel::notificationThreadFunction()
156165 continue ;
157166 }
158167
159- if (rc >= ZMQ_RESPONSE_BUFFER_SIZE )
168+ if (rc >= m_zmqResponseBufferSize )
160169 {
161170 SWSS_LOG_WARN (" zmq_recv message was truncated (over %d bytes, received %d), increase buffer size, message DROPPED" ,
162- ZMQ_RESPONSE_BUFFER_SIZE ,
171+ m_zmqResponseBufferSize ,
163172 rc);
164173
165174 continue ;
@@ -291,7 +300,7 @@ sai_status_t ZeroMQChannel::wait(
291300
292301 for (int i = 0 ; true ; ++i)
293302 {
294- rc = zmq_recv (m_socket, m_buffer.data (), ZMQ_RESPONSE_BUFFER_SIZE , 0 );
303+ rc = zmq_recv (m_socket, m_buffer.data (), m_zmqResponseBufferSize , 0 );
295304
296305 if (rc < 0 && zmq_errno () == EINTR && i < ZMQ_MAX_RETRY)
297306 {
@@ -301,10 +310,10 @@ sai_status_t ZeroMQChannel::wait(
301310 {
302311 SWSS_LOG_THROW (" zmq_recv failed, zmqerrno: %d" , zmq_errno ());
303312 }
304- if (rc >= ZMQ_RESPONSE_BUFFER_SIZE )
313+ if (rc >= m_zmqResponseBufferSize )
305314 {
306315 SWSS_LOG_THROW (" zmq_recv message was truncated (over %d bytes, received %d), increase buffer size, message DROPPED" ,
307- ZMQ_RESPONSE_BUFFER_SIZE ,
316+ m_zmqResponseBufferSize ,
308317 rc);
309318 }
310319 break ;
0 commit comments