-
Notifications
You must be signed in to change notification settings - Fork 0
/
sockethelper.h
53 lines (38 loc) · 1.06 KB
/
sockethelper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef SOCKETHELPER_H
#define SOCKETHELPER_H
#include <netinet/in.h>
#include <sys/un.h>
#include "common.h"
#define SOCKET_UNIX "unix"
#define SOCKET_INET "inet"
using namespace std;
class SocketHelper {
public:
SocketHelper(string socketType, int backlogQueue = 5);
void init();
void waitConnection();
JsonQuery getQuery(void);
void sendResponse(JsonResult response);
void end();
bool isUnix();
bool isInet();
bool isUnknown();
void setPort(int port);
void setSocketFile(string socketFile);
private:
static const int DEFAULT_SOCKET_FD = -1;
static const int DEFAULT_PORT = 8686;
string socketType, socketFile;
int serverSockfd, clientSockfd, port, backlogQueue;
socklen_t clilen;
struct sockaddr_in cli_addr_in;
struct sockaddr_un cli_addr_un;
void initSocketInet();
void initSocketUnix();
void waitConnectionInet();
void waitConnectionUnix();
void closeClient(bool force = false);
void closeServer();
void removeSocketFile();
};
#endif // SOCKETHELPER_H