-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSocket.h
74 lines (51 loc) · 1.52 KB
/
Socket.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
64
65
66
67
68
69
70
71
72
73
74
#include <string>
#include <vector>
#include <netinet/in.h>
#define UINT16 unsigned short
#define UINT unsigned int
#define ULONG unsigned long
#define TRUE 1
#define FALSE 0
#define BOOL unsigned char
#define VOID void
#define INT int
#define BYTE unsigned char
#define PVOID void*
#define PBYTE BYTE*
#define DWORD unsigned long
#define INT64 long long
#define UINT32 unsigned int
#define FALSE 0
#define TRUE 1
#define SOCKADDR_IN struct sockaddr_in
//#include "type.h"
// select mode
static const int SELECT_MODE_READY = 0x001;
static const int SELECT_MODE_WRITE = 0x002;
// select return codes
static const int SELECT_STATE_READY = 0;
static const int SELECT_STATE_ERROR = 1;
static const int SELECT_STATE_ABORTED = 2;
static const int SELECT_STATE_TIMEOUT = 3;
class Socket
{
public:
Socket(UINT mtu = 1500);
virtual ~Socket();
virtual void Close();
virtual int Write(BYTE* pBuffer, int writeSize, UINT nTimeOut = 500000); // 0.5sec
virtual int Read(BYTE* pBuffer, int readSize, UINT nTimeOut = 500000); // 0.5sec
virtual struct sockaddr_in GetBindAddr();
virtual struct sockaddr_in GetConnectAddr();
virtual UINT GetMTU();
//static BOOL GetLocalIPList(vector<string>& vIPList);
//static BOOL GetAdapterSpeed(vector<int>& vList);
protected:
void ReportError();
int Select(int iMode, int nTimeoutUsec);
BOOL m_isOpen;
int m_Socket;
struct sockaddr_in m_BindAddr;
struct sockaddr_in m_ConnectAddr;
UINT m_Mtu;
};