-
Notifications
You must be signed in to change notification settings - Fork 3
/
Ostype.h
106 lines (92 loc) · 1.92 KB
/
Ostype.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#ifndef __OS_TYPE_H__
#define __OS_TYPE_H__
#ifdef _WIN32
#include <WinSock2.h>
#include <WinBase.h>
#include <Windows.h>
#include <direct.h>
#else
#ifdef __APPLE__
#include <sys/event.h>
#include <sys/time.h>
#include <sys/syscall.h>
#else
#include <sys/epoll.h>
#endif
#include <pthread.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdint.h>
#include <signal.h>
#include <unistd.h>
#define closesocket close
#define ioctlsocket ioctl
#endif
#include <stdexcept>
#ifdef __GNUC__
#include <ext/hash_map>
using namespace __gnu_cxx;
namespace __gnu_cxx{
template<> struct hash<std::string>
{
size_t operator()(const std::string& x) const
{
return hash<const char*>()(x.c_str());
}
};
}
#else
#include <hash_map>
using namespace stdext;
#endif
#ifdef _WIN32
typedef char int8_t;
typedef short int16_t;
typedef int int32_t;
typedef long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
typedef int socklen_t;
#else
typedef int SOCKET;
typedef int BOOL;
#ifndef __APPLE__
const int TRUE = 1;
const int FALSE = 0;
#endif
const int SOCKET_ERROR = -1;
const int INVALID_SOCKET = -1;
#endif
typedef unsigned char uchar_t;
typedef int net_handle_t;
typedef int conn_handle_t;
enum
{
NETLIB_OK = 0,
NETLIB_ERROR = -1
};
#define NETLIB_INVALID_HANDLE -1
enum
{
NETLIB_MSG_CONNECT = 1,
NETLIB_MSG_CONFIRM,
NETLIB_MSG_READ,
NETLIB_MSG_WRITE,
NETLIB_MSG_CLOSE,
NETLIB_MSG_TIMER,
NETLIB_MSG_LOOP
};
const uint32_t INVALID_UINT32 = (uint32_t) -1;
const uint32_t INVALID_VALUE = 0;
typedef void (*callback_t) (void* callback_data, uint8_t msg, uint32_t handle, void* pParam);
#endif