Belle II Software development
UDPSocket.h
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#ifndef _B2ARICH_UDPSocket_hh_
9#define _B2ARICH_UDPSocket_hh_
10
11#include <string>
12
13#include <netinet/in.h>
14
15#include "daq/slc/system/FileDescriptor.h"
16
17namespace Belle2 {
23 class UDPSocket : public FileDescriptor {
24
25 friend class TCPServerSocket;
26
27 public:
28 UDPSocket();
29 UDPSocket(unsigned int port);
30 UDPSocket(unsigned int port,
31 const std::string& hostname,
32 bool boardcast = false);
33 UDPSocket(unsigned int port,
34 unsigned int addr,
35 bool boardcast = false);
36 virtual ~UDPSocket() {}
37
38 public:
39 int bind();
40 int bind(unsigned int port,
41 const std::string& hostname = "",
42 bool broadcast = true);
43 const std::string getHostName() const;
44 unsigned int getPort() const;
45 unsigned int getAddress() const;
46 const std::string getRemoteHostName() const;
47 unsigned int getRemotePort() const;
48 unsigned int getRemoteAddress() const;
49
50 public:
51 virtual size_t write(const void* v, size_t count);
52 virtual size_t read(void* v, size_t count);
53
54 private:
55 struct sockaddr_in m_addr;
56 struct sockaddr_in m_remote_addr;
57
58 private:
59 static unsigned int findSubnet(unsigned int addr);
60
61 };
62
64}
65
66#endif
67
Abstract base class for different kinds of events.