@@ -55,6 +55,8 @@ class ConsumerFMQchannel: public Consumer {
5555 int memoryPoolPageSize;
5656 int memoryPoolNumberOfPages;
5757
58+ std::vector<FairMQMessagePtr> messagesToSend; // collect HBF messages of each update
59+
5860 public:
5961
6062
@@ -226,8 +228,8 @@ class ConsumerFMQchannel: public Consumer {
226228
227229 // create a header message
228230 // std::unique_ptr<FairMQMessage> msgHeader(transportFactory->CreateMessage((void *)stfHeader, sizeof(SubTimeframe), cleanupCallback, (void *)(blockRef)));
229- std::unique_ptr<FairMQMessage> msgHeader (transportFactory-> CreateMessage (memoryBuffer,( void *)stfHeader, sizeof (SubTimeframe), ( void *)(blockRef) ));
230- sendingChannel->Send (msgHeader );
231+ assert (messagesToSend. empty ( ));
232+ messagesToSend. emplace_back ( std::move ( sendingChannel->NewMessage (memoryBuffer,( void *)stfHeader, sizeof (SubTimeframe), ( void *)(blockRef))) );
231233 // printf("sent header %d bytes\n",(int)sizeof(SubTimeframe));
232234
233235
@@ -254,7 +256,7 @@ class ConsumerFMQchannel: public Consumer {
254256 pendingFrames.push_back (pf);
255257 };
256258
257- auto pendingFramesSend = [&]() {
259+ auto pendingFramesCollect = [&]() {
258260 int nFrames=pendingFrames.size ();
259261
260262 if (nFrames==0 ) {
@@ -272,8 +274,9 @@ class ConsumerFMQchannel: public Consumer {
272274 void *hint=(void *)pendingFrames[0 ].blockRef ;
273275 // printf("block %p ix = %d : %d hint=%p\n",(void *)(&(b->data[ix])),ix,l,hint);
274276 // std::cout << typeid(pendingFrames[0].blockRef).name() << std::endl;
275- std::unique_ptr<FairMQMessage> msgBody (transportFactory->CreateMessage (memoryBuffer,(void *)(&(b->data [ix])),(size_t )(l),hint));
276- sendingChannel->Send (msgBody);
277+
278+ // create and queue a fmq message
279+ messagesToSend.emplace_back (std::move (sendingChannel->NewMessage (memoryBuffer,(void *)(&(b->data [ix])),(size_t )(l),hint)));
277280 // printf("sent single HB %d = %d bytes\n",pendingFrames[0].HBid,l);
278281 // printf("left to FMQ: %p\n",pendingFrames[0].blockRef);
279282
@@ -321,9 +324,8 @@ class ConsumerFMQchannel: public Consumer {
321324 // std::unique_ptr<FairMQMessage> msgBody(transportFactory->CreateMessage((void *)newBlock, totalSize, cleanupCallbackForMalloc, (void *)(newBlock)));
322325 // sendingChannel->Send(msgBody);
323326
324- // create a fmq message
325- std::unique_ptr<FairMQMessage> msgCopy (transportFactory->CreateMessage (memoryBuffer,(void *)newBlock, totalSize, (void *)(blockRef)));
326- sendingChannel->Send (msgCopy);
327+ // create and queue a fmq message
328+ messagesToSend.emplace_back (std::move (sendingChannel->NewMessage (memoryBuffer,(void *)newBlock, totalSize, (void *)(blockRef))));
327329
328330 // printf("sent reallocated HB %d (originally %d blocks) = %d bytes\n",pendingFrames[0].HBid,nFrames,totalSize);
329331 }
@@ -347,7 +349,7 @@ class ConsumerFMQchannel: public Consumer {
347349 pendingFramesAppend (HBstart,HBlength,lastHBid,br);
348350 }
349351 // send pending frames, if any
350- pendingFramesSend ();
352+ pendingFramesCollect ();
351353
352354 // update new HB frame
353355 HBstart=offset;
@@ -362,7 +364,13 @@ class ConsumerFMQchannel: public Consumer {
362364 }
363365
364366 // purge pendingFrames
365- pendingFramesSend ();
367+ pendingFramesCollect ();
368+
369+ // send all the messages
370+ if (sendingChannel->Send (messagesToSend) >= 0 )
371+ messagesToSend.clear ();
372+ else
373+ LOG (ERROR) << " Sending failed!" ;
366374
367375 /*
368376
0 commit comments