Belle II Software development
REvtSocket.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/dataflow/REvtSocket.h"
10
11using namespace Belle2;
12
13// REvtSocketRecv
14
15REvtSocketRecv::REvtSocketRecv(std::string host, int port)
16{
17 m_sock = new RSocketRecv(host.c_str(), (u_short)port);
18 m_recbuf = new char[MAXEVTSIZE];
19}
20
21REvtSocketRecv::~REvtSocketRecv()
22{
23 delete m_sock;
24 delete[] m_recbuf;
25}
26
27int REvtSocketRecv::send(EvtMessage* msg)
28{
29 // printf ( "REvtSocketRecv : sending = %d\n", msg->size() );
30 return m_sock->put((char*)msg->buffer(), msg->size());
31}
32
33EvtMessage* REvtSocketRecv::recv()
34{
35 int stat = m_sock->get(m_recbuf, MAXEVTSIZE);
36 if (stat <= 0) return NULL;
37 EvtMessage* evt = new EvtMessage(m_recbuf);
38 // delete [] evtbuf;
39 return evt;
40}
41
42int REvtSocketRecv::send_buffer(int nbytes, char* buf)
43{
44 return m_sock->put(buf, nbytes);
45}
46
47int REvtSocketRecv::recv_buffer(char* buf)
48{
49 int stat = m_sock->get(buf, MAXEVTSIZE);
50 return stat;
51}
52
53RSocketRecv* REvtSocketRecv::sock(void)
54{
55 return m_sock;
56}
57
58// REvtSocketSend
59
60REvtSocketSend::REvtSocketSend(int port, bool accept_at_init)
61{
62 m_sock = new RSocketSend((u_short)port);
63 m_recbuf = new char[MAXEVTSIZE];
64 if (accept_at_init)
65 m_sock->accept();
66}
67
68REvtSocketSend::~REvtSocketSend()
69{
70 delete m_sock;
71 delete[] m_recbuf;
72}
73
74EvtMessage* REvtSocketSend::REvtSocketSend::recv()
75{
76 int stat = m_sock->get(m_recbuf, MAXEVTSIZE);
77 if (stat <= 0) return NULL;
78 EvtMessage* evt = new EvtMessage(m_recbuf);
79 // delete [] evtbuf;
80 return evt;
81}
82
83int REvtSocketSend::send(EvtMessage* msg)
84{
85 return m_sock->put((char*)msg->buffer(), msg->size());
86}
87
88int REvtSocketSend::send_buffer(int nbytes, char* buf)
89{
90 return m_sock->put(buf, nbytes);
91}
92
93int REvtSocketSend::recv_buffer(char* buf)
94{
95 int stat = m_sock->get(buf, MAXEVTSIZE);
96 return stat;
97}
98
99RSocketSend* REvtSocketSend::sock(void)
100{
101 return m_sock;
102}
Class to manage streamed object.
Definition: EvtMessage.h:59
char * buffer()
Get buffer address.
Definition: EvtMessage.cc:76
int size() const
Get size of message including headers.
Definition: EvtMessage.cc:94
Abstract base class for different kinds of events.