Belle II Software development
TCPSocket.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_TCPSocket_hh_
9#define _B2ARICH_TCPSocket_hh_
10
11#include <string>
12
13#include "daq/slc/system/FileDescriptor.h"
14
15namespace Belle2 {
21 class TCPSocket : public FileDescriptor {
22
23 friend class TCPServerSocket;
24
25 public:
26 TCPSocket() : m_ip(""), m_port(0) {}
27 TCPSocket(const std::string& ip, unsigned short port)
28 : m_ip(ip), m_port(port) {}
29 virtual ~TCPSocket() {}
30
31 private:
32 TCPSocket(int fd) : FileDescriptor(fd), m_ip(""), m_port(0) {}
33
34 public:
35 void setIP(const std::string& ip) { m_ip = ip; }
36 void setPort(unsigned short port) { m_port = port; }
37 const std::string& getIP() const { return m_ip; }
38 unsigned short getPort() const { return m_port; }
39 int connect();
40 int connect(const std::string& ip, unsigned short port);
41 void setBufferSize(int size);
42 void print();
43 const std::string getLocalIP();
44 int getLocalAddress();
45 int getLocalPort();
46 unsigned int getAddress();
47
48 public:
49 virtual size_t write(const void* v, size_t count);
50 virtual size_t read(void* v, size_t count);
51 size_t read_once(void* v, size_t count);
52
53 private:
54 std::string m_ip;
55 unsigned short m_port;
56
57 };
58
60}
61
62#endif
63
Abstract base class for different kinds of events.