Belle II Software development
EvtSocket.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/EvtSocket.h"
10
11using namespace Belle2;
12
13// EvtSocketSend
14
15EvtSocketSend::EvtSocketSend(std::string host, int port)
16{
17 m_sock = new SocketSend(host.c_str(), (u_short)port);
18 m_recbuf = new char[MAXEVTSIZE];
19}
20
21EvtSocketSend::~EvtSocketSend()
22{
23 delete m_sock;
24 delete[] m_recbuf;
25}
26
27int EvtSocketSend::send(EvtMessage* msg)
28{
29 // printf ( "EvtSocketSend : sending = %d\n", msg->size() );
30 return m_sock->put((char*)msg->buffer(), msg->size());
31}
32
33EvtMessage* EvtSocketSend::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 EvtSocketSend::send_buffer(int nbytes, char* buf)
43{
44 return m_sock->put(buf, nbytes);
45}
46
47int EvtSocketSend::recv_buffer(char* buf)
48{
49 int stat = m_sock->get(buf, MAXEVTSIZE);
50 return stat;
51}
52
53int EvtSocketSend::recv_pxd_buffer(char* buf)
54{
55 int stat = m_sock->get_pxd(buf, MAXEVTSIZE);
56 return stat;
57}
58
59SocketSend* EvtSocketSend::sock(void)
60{
61 return m_sock;
62}
63
64
65// EvtSocketRecv
66
67EvtSocketRecv::EvtSocketRecv(int port, bool accept_at_init)
68{
69 m_sock = new SocketRecv((u_short)port);
70 m_recbuf = new char[MAXEVTSIZE];
71 if (accept_at_init)
72 m_sock->accept();
73}
74
75EvtSocketRecv::~EvtSocketRecv()
76{
77 delete m_sock;
78 delete[] m_recbuf;
79}
80
81EvtMessage* EvtSocketRecv::recv()
82{
83 int stat = m_sock->get(m_recbuf, MAXEVTSIZE);
84 if (stat <= 0) return NULL;
85 EvtMessage* evt = new EvtMessage(m_recbuf);
86 // delete [] evtbuf;
87 return evt;
88}
89
90int EvtSocketRecv::send(EvtMessage* msg)
91{
92 return m_sock->put((char*)msg->buffer(), msg->size());
93}
94
95int EvtSocketRecv::send_buffer(int nbytes, char* buf)
96{
97 return m_sock->put(buf, nbytes);
98}
99
100int EvtSocketRecv::recv_buffer(char* buf)
101{
102 int stat = m_sock->get(buf, MAXEVTSIZE);
103 return stat;
104}
105
106SocketRecv* EvtSocketRecv::sock(void)
107{
108 return m_sock;
109}
110
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.