Belle II Software development
SocketLib.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 SOCKETLIB_H
9#define SOCKETLIB_H
10
11#include <netdb.h>
12#include <netinet/in.h>
13
14#define D2_SOCKBUF_SIZE 8000000
15
16typedef unsigned short u_short;
17
18namespace Belle2 {
23
24
25 class SocketIO {
26 public:
27 SocketIO();
28 ~SocketIO();
29
30 static int put(int sock, char* data, int len);
31 static int put_wordbuf(int sock, int* data, int len);
32 int get(int sock, char* data, int len);
33 int get_wordbuf(int sock, int* data, int len);
34
35 int get_pxd(int sock, char* data, int len);
36
37 // protected:
38 int read_data(int sock, char* data, int len);
39 static int write_data(int sock, char* data, int len);
40
41 void interrupt();
42
43 private:
44 int m_int = 0;
45
46 };
47
48 class SocketRecv : public SocketIO {
49 public:
50 explicit SocketRecv(u_short port);
51 ~SocketRecv();
52
53 int examine();
54 int accept();
55 int close();
56
57 int sock() const;
58 int sender() const;
59 void sock(int sockid);
60
61 int get(char* data, int len);
62 int get_wordbuf(int* data, int len);
63 int read(char* data, int len);
64 int put(char* data, int len);
65 int write(char* data, int len);
66
67 int err() const;
68 // cppcheck-suppress duplInheritedMember ; the derived class deliberately provides its own
69 void interrupt();
70
71 private:
72 SocketIO m_io;
73 int m_sock;
74 int m_sender;
75 int m_errno;
76
77 };
78
79 class SocketSend : public SocketIO {
80 public:
81 SocketSend(const char* node, u_short prt);
82 ~SocketSend();
83
84 int reconnect(int ntry);
85
86 int put(char* data, int len);
87 int put_wordbuf(int* data, int len);
88 int write(char* data, int len);
89 int get(char* data, int len);
90 int get_pxd(char* data, int len);
91 int read(char* data, int len);
92
93 char* node(void);
94 int port(void);
95 int sock(void);
96 void sock(int sockid);
97
98 int err(void);
99
100 private:
101 SocketIO m_io;
102 struct hostent* m_hp;
103 struct sockaddr_in m_sa;
104 int m_sock;
105 int m_port;
106 char m_node[128];
107 int m_errno;
108
109 };
110
112}
113#endif
114
115
116
117
118
119
int get_pxd(int sock, char *data, int len)
Definition SocketLib.cc:126
Abstract base class for different kinds of events.