Belle II Software development
RevSock2Rb.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/RevSock2Rb.h"
10
11#include <unistd.h>
12
13using namespace std;
14using namespace Belle2;
15
16RevSock2Rb::RevSock2Rb(string rbuf, string src, int port, string shmname, int id)
17{
18 // m_rbuf = new RingBuffer(rbuf.c_str(), RBUFSIZE);
19 m_rbuf = new RingBuffer(rbuf.c_str());
20 m_sock = new REvtSocketRecv(src, port);
21 m_evtbuf = new char[MAXEVTSIZE];
22 m_flow = new RFFlowStat((char*)shmname.c_str(), id, m_rbuf);
23
24}
25
26RevSock2Rb::~RevSock2Rb(void)
27{
28 delete m_sock;
29 delete m_rbuf;
30}
31
33{
34 // Get a record from socket
35 EvtMessage* msg = m_sock->recv();
36 if (msg == NULL) {
37 return 0;
38 }
39 // B2INFO ( "Rx: got an event from Socket, size=" << msg->size() );
40 if (msg->type() == MSG_TERMINATE) {
41 return 0;
42 // Flag End Of File !!!!!
43 // return msg->type(); // EOF
44 }
45 m_flow->log(msg->size());
46
47 // Put the message in ring buffer
48 int stat = 0;
49 for (;;) {
50 stat = m_rbuf->insq((int*)msg->buffer(), msg->paddedSize());
51 if (stat >= 0) break;
52 // usleep(100);
53 usleep(20);
54 }
55 delete msg;
56 return stat;
57}
58
59int RevSock2Rb::Reconnect(int ntimes)
60{
61 return (m_sock->sock())->reconnect(ntimes);
62}
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
int size() const
Get size of message including headers.
Definition: EvtMessage.cc:94
int ReceiveEvent(void)
Event function.
Definition: RevSock2Rb.cc:32
int Reconnect(int ntry)
Reconnect.
Definition: RevSock2Rb.cc:59
RevSock2Rb(std::string rbuf, std::string src, int port, std::string shmname, int id)
Constuctor and Destructor.
Definition: RevSock2Rb.cc:16
Class to manage a Ring Buffer placed in an IPC shared memory.
Definition: RingBuffer.h:39
int insq(const int *buf, int size, bool checkTx=false)
Append a buffer to the RingBuffer.
Definition: RingBuffer.cc:189
Abstract base class for different kinds of events.
STL namespace.