Belle II Software  release-05-02-19
UDPSocket.h
1 #ifndef _B2ARICH_UDPSocket_hh_
2 #define _B2ARICH_UDPSocket_hh_
3 
4 #include <string>
5 
6 #include <netinet/in.h>
7 
8 #include "daq/slc/system/FileDescriptor.h"
9 
10 namespace Belle2 {
16  class UDPSocket : public FileDescriptor {
17 
18  friend class TCPServerSocket;
19 
20  public:
21  UDPSocket();
22  UDPSocket(unsigned int port);
23  UDPSocket(unsigned int port,
24  const std::string& hostname,
25  bool boardcast = false);
26  UDPSocket(unsigned int port,
27  unsigned int addr,
28  bool boardcast = false);
29  virtual ~UDPSocket() {}
30 
31  public:
32  int bind();
33  int bind(unsigned int port,
34  const std::string& hostname = "",
35  bool broadcast = true);
36  const std::string getHostName() const;
37  unsigned int getPort() const;
38  unsigned int getAddress() const;
39  const std::string getRemoteHostName() const;
40  unsigned int getRemotePort() const;
41  unsigned int getRemoteAddress() const;
42 
43  public:
44  virtual size_t write(const void* v, size_t count);
45  virtual size_t read(void* v, size_t count);
46 
47  private:
48  struct sockaddr_in m_addr;
49  struct sockaddr_in m_remote_addr;
50 
51  private:
52  static unsigned int findSubnet(unsigned int addr);
53 
54  };
55 
57 }
58 
59 #endif
60 
Belle2::UDPSocket
Definition: UDPSocket.h:16
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TCPServerSocket
Definition: TCPServerSocket.h:13
Belle2::FileDescriptor
Definition: FileDescriptor.h:10