Belle II Software  release-08-01-10
RawRevSock2Rb.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/RawRevSock2Rb.h"
10 #include "daq/dataflow/REvtSocket.h"
11 
12 #include <unistd.h>
13 
14 using namespace std;
15 using namespace Belle2;
16 
17 RawRevSock2Rb::RawRevSock2Rb(string rbuf, string src, int port, string shmname, int id)
18 {
19  // m_rbuf = new RingBuffer(rbuf.c_str(), RBUFSIZE);
20  m_rbuf = new RingBuffer(rbuf.c_str());
21  m_sock = new RSocketRecv(src.c_str(), (u_int)port);
22  m_evtbuf = new char[MAXEVTSIZE];
23  m_flow = new RFFlowStat((char*)shmname.c_str(), id, m_rbuf);
24  m_buf = new int[MAXBUFSIZE];
25 
26 }
27 
28 RawRevSock2Rb::~RawRevSock2Rb(void)
29 {
30  delete m_sock;
31  delete m_rbuf;
32 }
33 
35 {
36  // Get a record from socket
37  int bufsize = m_sock->get_wordbuf(m_buf, MAXBUFSIZE);
38 
39  if (bufsize <= 0) {
40  return 0;
41  }
42  m_flow->log(bufsize * 4);
43 
44  // Put the message in ring buffer
45  int stat = 0;
46  for (;;) {
47  stat = m_rbuf->insq(m_buf, bufsize);
48  if (stat >= 0) break;
49  // usleep(100);
50  usleep(20);
51  }
52  return stat;
53 }
54 
55 int RawRevSock2Rb::Reconnect(int ntimes)
56 {
57  return m_sock->reconnect(ntimes);
58 }
59 
60 
Class to manage a Ring Buffer placed in an IPC shared memory.
Definition: RingBuffer.h:39
RawRevSock2Rb(std::string rbuf, std::string src, int port, std::string shmname, int id)
Constuctor and Destructor.
int ReceiveEvent(void)
Event function.
int Reconnect(int ntry)
Reconnect.
Abstract base class for different kinds of events.