forked from awwit/httpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSocket.h
More file actions
76 lines (57 loc) · 1.79 KB
/
Socket.h
File metadata and controls
76 lines (57 loc) · 1.79 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once
#include "System.h"
#include <vector>
#include <string>
#include <chrono>
namespace HttpServer
{
class Socket
{
protected:
System::native_socket_type socket_handle;
public:
bool static Startup();
bool static Cleanup();
int static getLastError();
public:
Socket();
Socket(const System::native_socket_type fd);
Socket(const Socket &obj);
Socket(Socket &&obj);
~Socket() = default;
bool open();
bool close();
bool is_open() const;
System::native_socket_type get_handle() const;
bool bind(const int port) const;
bool listen() const;
Socket accept() const;
Socket nonblock_accept() const;
Socket nonblock_accept(const std::chrono::milliseconds &timeout) const;
bool shutdown() const;
bool nonblock(const bool isNonBlock = true) const;
// bool is_nonblock() const;
bool tcp_nodelay(const bool nodelay = true) const;
long recv(std::vector<std::string::value_type> &buf) const;
long nonblock_recv(std::vector<std::string::value_type> &buf, const std::chrono::milliseconds &timeout) const;
long send(const std::string &buf) const;
long send(const std::vector<std::string::value_type> &buf, const size_t length) const;
long nonblock_send(const std::string &buf, const std::chrono::milliseconds &timeout) const;
long nonblock_send(const std::vector<std::string::value_type> &buf, const size_t length, const std::chrono::milliseconds &timeout) const;
void nonblock_send_sync() const;
Socket &operator =(const Socket &obj);
bool operator ==(const Socket &obj) const;
bool operator !=(const Socket &obj) const;
};
};
namespace std
{
// Hash for Socket
template<> struct hash<HttpServer::Socket>
{
std::size_t operator()(const HttpServer::Socket &obj) const
{
return std::hash<System::native_socket_type>{}(obj.get_handle() );
}
};
};