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 {
25 class SocketIO {
26 public:
27 SocketIO();
28 ~SocketIO();
29
30 int put(int sock, char* data, int len);
31 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 int write_data(int sock, char* data, int len);
40
41 void interrupt();
42
43 private:
44 int m_int;
45
46 };
47
48 class SocketRecv : public SocketIO {
49 public:
50 SocketRecv(u_short port);
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 void interrupt();
69
70 private:
71 SocketIO m_io;
72 int m_sock;
73 int m_sender;
74 int m_errno;
75
76 };
77
78 class SocketSend : public SocketIO {
79 public:
80 SocketSend(const char* node, u_short prt);
82
83 int reconnect(int ntry);
84
85 int put(char* data, int len);
86 int put_wordbuf(int* data, int len);
87 int write(char* data, int len);
88 int get(char* data, int len);
89 int get_pxd(char* data, int len);
90 int read(char* data, int len);
91
92 char* node(void);
93 int port(void);
94 int sock(void);
95 void sock(int sockid);
96
97 int err(void);
98
99 private:
100 SocketIO m_io;
101 struct hostent* m_hp;
102 struct sockaddr_in m_sa;
103 int m_sock;
104 int m_port;
105 char m_node[128];
106 int m_errno;
107
108 };
109
111}
112#endif
113
114
115
116
117
118
int get_pxd(int sock, char *data, int len)
Definition: SocketLib.cc:126
Abstract base class for different kinds of events.