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
81 lines (60 loc) · 2.22 KB
/
Socket.h
File metadata and controls
81 lines (60 loc) · 2.22 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
77
78
79
80
81
#pragma once
#include "../system/System.h"
#include <vector>
#include <string>
#include <chrono>
namespace Socket
{
class Socket
{
protected:
System::native_socket_type socket_handle;
public:
bool static Startup() noexcept;
bool static Cleanup() noexcept;
int static getLastError() noexcept;
public:
Socket() noexcept;
Socket(const System::native_socket_type fd) noexcept;
Socket(const Socket &obj) noexcept;
Socket(Socket &&obj) noexcept;
~Socket() noexcept = default;
bool open() noexcept;
bool close() noexcept;
bool is_open() const noexcept;
System::native_socket_type get_handle() const noexcept;
bool bind(const int port) const noexcept;
bool listen() const noexcept;
Socket accept() const noexcept;
Socket nonblock_accept() const noexcept;
Socket nonblock_accept(const std::chrono::milliseconds &timeout) const noexcept;
bool shutdown() const noexcept;
bool nonblock(const bool isNonBlock = true) const noexcept;
// bool is_nonblock() const noexcept;
bool tcp_nodelay(const bool nodelay = true) const noexcept;
long recv(std::vector<std::string::value_type> &buf) const noexcept;
long recv(void *buf, const size_t length) const noexcept;
long nonblock_recv(std::vector<std::string::value_type> &buf, const std::chrono::milliseconds &timeout) const noexcept;
long nonblock_recv(void *buf, const size_t length, const std::chrono::milliseconds &timeout) const noexcept;
void nonblock_recv_sync() const noexcept;
long send(const std::string &buf) const noexcept;
long send(const void *buf, const size_t length) const noexcept;
long nonblock_send(const std::string &buf, const std::chrono::milliseconds &timeout) const noexcept;
long nonblock_send(const void *buf, const size_t length, const std::chrono::milliseconds &timeout) const noexcept;
void nonblock_send_sync() const noexcept;
Socket &operator =(const Socket &obj) noexcept;
bool operator ==(const Socket &obj) const noexcept;
bool operator !=(const Socket &obj) const noexcept;
};
};
namespace std
{
// Hash for Socket
template<> struct hash<Socket::Socket>
{
std::size_t operator()(const Socket::Socket &obj) const noexcept
{
return std::hash<System::native_socket_type>{}(obj.get_handle() );
}
};
};