Belle II Software  release-08-01-10
Sock2Rb.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/Sock2Rb.h"
10 
11 #include <unistd.h>
12 
13 using namespace std;
14 using namespace Belle2;
15 
16 Sock2Rb::Sock2Rb(string rbuf, int port)
17 {
18  // m_rbuf = new RingBuffer(rbuf.c_str(), RBUFSIZE);
19  m_rbuf = new RingBuffer(rbuf.c_str());
20  m_sock = new EvtSocketRecv(port);
21  m_evtbuf = new char[MAXEVTSIZE];
22 
23 }
24 
25 Sock2Rb::~Sock2Rb(void)
26 {
27  delete m_sock;
28  delete m_rbuf;
29 }
30 
31 int Sock2Rb::ReceiveEvent(void)
32 {
33  // Get a record from socket
34  EvtMessage* msg = m_sock->recv();
35  if (msg == NULL) {
36  return 0;
37  }
38  // B2INFO ( "Rx: got an event from Socket, size=" << msg->size() );
39  if (msg->type() == MSG_TERMINATE) {
40  return 0;
41  // Flag End Of File !!!!!
42  // return msg->type(); // EOF
43  }
44 
45  // Put the message in ring buffer
46  int stat = 0;
47  for (;;) {
48  stat = m_rbuf->insq((int*)msg->buffer(), msg->paddedSize());
49  if (stat >= 0) break;
50  // usleep(100);
51  usleep(20);
52  }
53  delete msg;
54  return stat;
55 }
56 
Class to manage streamed object.
Definition: EvtMessage.h:59
int paddedSize() const
Same as size(), but as size of an integer array.
Definition: EvtMessage.cc:99
ERecordType type() const
Get record type.
Definition: EvtMessage.cc:114
char * buffer()
Get buffer address.
Definition: EvtMessage.cc:76
Class to manage a Ring Buffer placed in an IPC shared memory.
Definition: RingBuffer.h:39
Abstract base class for different kinds of events.