-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSocketLibSocket.h
More file actions
89 lines (71 loc) · 1.43 KB
/
SocketLibSocket.h
File metadata and controls
89 lines (71 loc) · 1.43 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
82
83
84
85
86
87
88
#ifndef SOCKETLIBSOCKET_H
#define SOCKETLIBSOCKET_H
#include "BasicLib.h"
#include "SocketLibTypes.h"
#include "SocketLibErrors.h"
namespace SocketLib
{
class Socket
{
protected:
Socket(sock p_socket = -1);
sock m_sock;
struct sockaddr_in m_localinfo;
bool m_isblocking;
public:
inline sock GetSock() const
{
return m_sock;
}
inline port GetLocalPort() const
{
return ntohs(m_localinfo.sin_port);
}
inline ipaddress GetLocalAddress() const
{
return m_localinfo.sin_addr.S_un.S_addr;
}
void Close();
void SetBlocking(bool p_blockmode);
};
class DataSocket : public Socket
{
protected:
bool m_connected;
// about the remote connection addr;
struct sockaddr_in m_remoteinfo;
public:
DataSocket(sock p_socket = -1);
inline ipaddress GetRemoteAddress() const
{
return m_remoteinfo.sin_addr.S_un.S_addr;
}
inline port GetRemotePort() const
{
return ntohs(m_remoteinfo.sin_port);
}
inline bool IsConnected() const
{
return m_connected;
}
void Connect(ipaddress p_addr, port p_port);
int Send(const char* p_buffer, int p_size);
int Receive(char* p_buffer, int p_size);
void Close();
};
class ListeningSocket : public Socket
{
protected:
bool m_listening;
public:
ListeningSocket();
void Listen(port p_port);
DataSocket Accept();
inline bool IsListening() const
{
return m_listening;
}
void Close();
};
};
#endif // !SOCKETLIBSOCKET_H