Belle II Software  release-08-01-10
Rb2Sock.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include "daq/rfarm/event/Rb2Sock.h"
10 
11 #include <unistd.h>
12 
13 using namespace std;
14 using namespace Belle2;
15 
16 Rb2Sock::Rb2Sock(string rbuf, string dest, int port)
17 {
18  // m_rbuf = new RingBuffer(rbuf.c_str(), RBUFSIZE);
19  m_rbuf = new RingBuffer(rbuf.c_str());
20  m_sock = new EvtSocketSend(dest, port);
21  m_evtbuf = new char[MAXEVTSIZE];
22 
23 }
24 
25 Rb2Sock::~Rb2Sock(void)
26 {
27  delete m_sock;
28  delete m_rbuf;
29 }
30 
31 int Rb2Sock::SendEvent(void)
32 {
33  // Get a record from ringbuf
34  int size;
35  while ((size = m_rbuf->remq((int*)m_evtbuf)) == 0) {
36  // printf ( "Rx : evtbuf is not available yet....\n" );
37  // usleep(100);
38  usleep(20);
39  }
40 
41  EvtMessage* msg = new EvtMessage(m_evtbuf); // Ptr copy, no overhead
42 
43  if (msg->type() == MSG_TERMINATE) {
44  printf("EoF found. Exitting.....\n");
45  m_sock->send(msg);
46  delete msg;
47  return -1;
48  } else {
49  int is = m_sock->send(msg);
50  delete msg;
51  return is;
52  // return msg->size();
53  }
54 }
55 
Class to manage streamed object.
Definition: EvtMessage.h:59
ERecordType type() const
Get record type.
Definition: EvtMessage.cc:114
Class to manage a Ring Buffer placed in an IPC shared memory.
Definition: RingBuffer.h:39
Abstract base class for different kinds of events.