forked from skyfireitdiy/sflib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsf_tcp_client_linux.h
63 lines (43 loc) · 1.18 KB
/
sf_tcp_client_linux.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
54
55
56
57
58
59
60
61
62
63
/**
* @version 1.0.0
* @author skyfire
* @mail [email protected]
* @see http://github.com/skyfireitdiy/sflib
* @file sf_tcp_client_linux.h
* sflib第一版本发布
* 版本号1.0.0
* 发布日期:2018-10-22
*/
#pragma once
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string>
#include <functional>
#include <memory>
#include <cstring>
#include <thread>
#include "sf_tcp_client_interface.h"
namespace skyfire
{
class sf_tcp_client : public sf_tcp_client_interface
{
private:
bool inited__ = false;
bool raw__ = false;
int sock__ = -1;
public:
sf_tcp_client(bool raw = false);
SOCKET get_raw_socket() override;
bool bind(const std::string& ip, unsigned short port) override;
static std::shared_ptr<sf_tcp_client> make_client(bool raw = false);
~sf_tcp_client();
bool connect_to_server(const std::string &ip, unsigned short port) override;
bool send(int type, const byte_array &data) override;
bool send(const byte_array &data) override;
void close() override;
};
}