renet 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/renet/extconf.rb +1 -1
- data/ext/renet/renet.c +1 -1
- data/ext/renet/renet.h +1 -1
- metadata +2 -20
- data/ext/renet/callbacks.c +0 -47
- data/ext/renet/callbacks.h +0 -27
- data/ext/renet/compress.c +0 -654
- data/ext/renet/enet.h +0 -540
- data/ext/renet/host.c +0 -479
- data/ext/renet/list.c +0 -75
- data/ext/renet/list.h +0 -43
- data/ext/renet/packet.c +0 -157
- data/ext/renet/peer.c +0 -816
- data/ext/renet/protocol.c +0 -1671
- data/ext/renet/protocol.h +0 -196
- data/ext/renet/time.h +0 -18
- data/ext/renet/types.h +0 -13
- data/ext/renet/unix.c +0 -446
- data/ext/renet/unix.h +0 -45
- data/ext/renet/utility.h +0 -12
- data/ext/renet/win32.c +0 -348
- data/ext/renet/win32.h +0 -58
data/ext/renet/unix.h
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
@file unix.h
|
3
|
-
@brief ENet Unix header
|
4
|
-
*/
|
5
|
-
#ifndef __ENET_UNIX_H__
|
6
|
-
#define __ENET_UNIX_H__
|
7
|
-
|
8
|
-
#include <stdlib.h>
|
9
|
-
#include <sys/time.h>
|
10
|
-
#include <sys/types.h>
|
11
|
-
#include <netinet/in.h>
|
12
|
-
#include <unistd.h>
|
13
|
-
|
14
|
-
typedef int ENetSocket;
|
15
|
-
|
16
|
-
enum
|
17
|
-
{
|
18
|
-
ENET_SOCKET_NULL = -1
|
19
|
-
};
|
20
|
-
|
21
|
-
#define ENET_HOST_TO_NET_16(value) (htons (value)) /**< macro that converts host to net byte-order of a 16-bit value */
|
22
|
-
#define ENET_HOST_TO_NET_32(value) (htonl (value)) /**< macro that converts host to net byte-order of a 32-bit value */
|
23
|
-
|
24
|
-
#define ENET_NET_TO_HOST_16(value) (ntohs (value)) /**< macro that converts net to host byte-order of a 16-bit value */
|
25
|
-
#define ENET_NET_TO_HOST_32(value) (ntohl (value)) /**< macro that converts net to host byte-order of a 32-bit value */
|
26
|
-
|
27
|
-
typedef struct
|
28
|
-
{
|
29
|
-
void * data;
|
30
|
-
size_t dataLength;
|
31
|
-
} ENetBuffer;
|
32
|
-
|
33
|
-
#define ENET_CALLBACK
|
34
|
-
|
35
|
-
#define ENET_API extern
|
36
|
-
|
37
|
-
typedef fd_set ENetSocketSet;
|
38
|
-
|
39
|
-
#define ENET_SOCKETSET_EMPTY(sockset) FD_ZERO (& (sockset))
|
40
|
-
#define ENET_SOCKETSET_ADD(sockset, socket) FD_SET (socket, & (sockset))
|
41
|
-
#define ENET_SOCKETSET_REMOVE(sockset, socket) FD_CLEAR (socket, & (sockset))
|
42
|
-
#define ENET_SOCKETSET_CHECK(sockset, socket) FD_ISSET (socket, & (sockset))
|
43
|
-
|
44
|
-
#endif /* __ENET_UNIX_H__ */
|
45
|
-
|
data/ext/renet/utility.h
DELETED
data/ext/renet/win32.c
DELETED
@@ -1,348 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
@file win32.c
|
3
|
-
@brief ENet Win32 system specific functions
|
4
|
-
*/
|
5
|
-
#ifdef WIN32
|
6
|
-
|
7
|
-
#include <time.h>
|
8
|
-
#define ENET_BUILDING_LIB 1
|
9
|
-
#include "enet.h"
|
10
|
-
|
11
|
-
static enet_uint32 timeBase = 0;
|
12
|
-
|
13
|
-
int
|
14
|
-
enet_initialize (void)
|
15
|
-
{
|
16
|
-
WORD versionRequested = MAKEWORD (1, 1);
|
17
|
-
WSADATA wsaData;
|
18
|
-
|
19
|
-
if (WSAStartup (versionRequested, & wsaData))
|
20
|
-
return -1;
|
21
|
-
|
22
|
-
if (LOBYTE (wsaData.wVersion) != 1||
|
23
|
-
HIBYTE (wsaData.wVersion) != 1)
|
24
|
-
{
|
25
|
-
WSACleanup ();
|
26
|
-
|
27
|
-
return -1;
|
28
|
-
}
|
29
|
-
|
30
|
-
timeBeginPeriod (1);
|
31
|
-
|
32
|
-
return 0;
|
33
|
-
}
|
34
|
-
|
35
|
-
void
|
36
|
-
enet_deinitialize (void)
|
37
|
-
{
|
38
|
-
timeEndPeriod (1);
|
39
|
-
|
40
|
-
WSACleanup ();
|
41
|
-
}
|
42
|
-
|
43
|
-
enet_uint32
|
44
|
-
enet_time_get (void)
|
45
|
-
{
|
46
|
-
return (enet_uint32) timeGetTime () - timeBase;
|
47
|
-
}
|
48
|
-
|
49
|
-
void
|
50
|
-
enet_time_set (enet_uint32 newTimeBase)
|
51
|
-
{
|
52
|
-
timeBase = (enet_uint32) timeGetTime () - newTimeBase;
|
53
|
-
}
|
54
|
-
|
55
|
-
int
|
56
|
-
enet_address_set_host (ENetAddress * address, const char * name)
|
57
|
-
{
|
58
|
-
struct hostent * hostEntry;
|
59
|
-
|
60
|
-
hostEntry = gethostbyname (name);
|
61
|
-
if (hostEntry == NULL ||
|
62
|
-
hostEntry -> h_addrtype != AF_INET)
|
63
|
-
{
|
64
|
-
unsigned long host = inet_addr (name);
|
65
|
-
if (host == INADDR_NONE)
|
66
|
-
return -1;
|
67
|
-
address -> host = host;
|
68
|
-
return 0;
|
69
|
-
}
|
70
|
-
|
71
|
-
address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0];
|
72
|
-
|
73
|
-
return 0;
|
74
|
-
}
|
75
|
-
|
76
|
-
int
|
77
|
-
enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength)
|
78
|
-
{
|
79
|
-
char * addr = inet_ntoa (* (struct in_addr *) & address -> host);
|
80
|
-
if (addr == NULL)
|
81
|
-
return -1;
|
82
|
-
strncpy (name, addr, nameLength);
|
83
|
-
return 0;
|
84
|
-
}
|
85
|
-
|
86
|
-
int
|
87
|
-
enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength)
|
88
|
-
{
|
89
|
-
struct in_addr in;
|
90
|
-
struct hostent * hostEntry;
|
91
|
-
|
92
|
-
in.s_addr = address -> host;
|
93
|
-
|
94
|
-
hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET);
|
95
|
-
if (hostEntry == NULL)
|
96
|
-
return enet_address_get_host_ip (address, name, nameLength);
|
97
|
-
|
98
|
-
strncpy (name, hostEntry -> h_name, nameLength);
|
99
|
-
|
100
|
-
return 0;
|
101
|
-
}
|
102
|
-
|
103
|
-
int
|
104
|
-
enet_socket_bind (ENetSocket socket, const ENetAddress * address)
|
105
|
-
{
|
106
|
-
struct sockaddr_in sin;
|
107
|
-
|
108
|
-
memset (& sin, 0, sizeof (struct sockaddr_in));
|
109
|
-
|
110
|
-
sin.sin_family = AF_INET;
|
111
|
-
|
112
|
-
if (address != NULL)
|
113
|
-
{
|
114
|
-
sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
|
115
|
-
sin.sin_addr.s_addr = address -> host;
|
116
|
-
}
|
117
|
-
else
|
118
|
-
{
|
119
|
-
sin.sin_port = 0;
|
120
|
-
sin.sin_addr.s_addr = INADDR_ANY;
|
121
|
-
}
|
122
|
-
|
123
|
-
return bind (socket,
|
124
|
-
(struct sockaddr *) & sin,
|
125
|
-
sizeof (struct sockaddr_in)) == SOCKET_ERROR ? -1 : 0;
|
126
|
-
}
|
127
|
-
|
128
|
-
int
|
129
|
-
enet_socket_listen (ENetSocket socket, int backlog)
|
130
|
-
{
|
131
|
-
return listen (socket, backlog < 0 ? SOMAXCONN : backlog) == SOCKET_ERROR ? -1 : 0;
|
132
|
-
}
|
133
|
-
|
134
|
-
ENetSocket
|
135
|
-
enet_socket_create (ENetSocketType type)
|
136
|
-
{
|
137
|
-
return socket (PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
|
138
|
-
}
|
139
|
-
|
140
|
-
int
|
141
|
-
enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value)
|
142
|
-
{
|
143
|
-
int result = SOCKET_ERROR;
|
144
|
-
switch (option)
|
145
|
-
{
|
146
|
-
case ENET_SOCKOPT_NONBLOCK:
|
147
|
-
{
|
148
|
-
u_long nonBlocking = (u_long) value;
|
149
|
-
result = ioctlsocket (socket, FIONBIO, & nonBlocking);
|
150
|
-
break;
|
151
|
-
}
|
152
|
-
|
153
|
-
case ENET_SOCKOPT_BROADCAST:
|
154
|
-
result = setsockopt (socket, SOL_SOCKET, SO_BROADCAST, (char *) & value, sizeof (int));
|
155
|
-
break;
|
156
|
-
|
157
|
-
case ENET_SOCKOPT_REUSEADDR:
|
158
|
-
result = setsockopt (socket, SOL_SOCKET, SO_REUSEADDR, (char *) & value, sizeof (int));
|
159
|
-
break;
|
160
|
-
|
161
|
-
case ENET_SOCKOPT_RCVBUF:
|
162
|
-
result = setsockopt (socket, SOL_SOCKET, SO_RCVBUF, (char *) & value, sizeof (int));
|
163
|
-
break;
|
164
|
-
|
165
|
-
case ENET_SOCKOPT_SNDBUF:
|
166
|
-
result = setsockopt (socket, SOL_SOCKET, SO_SNDBUF, (char *) & value, sizeof (int));
|
167
|
-
break;
|
168
|
-
|
169
|
-
default:
|
170
|
-
break;
|
171
|
-
}
|
172
|
-
return result == SOCKET_ERROR ? -1 : 0;
|
173
|
-
}
|
174
|
-
|
175
|
-
int
|
176
|
-
enet_socket_connect (ENetSocket socket, const ENetAddress * address)
|
177
|
-
{
|
178
|
-
struct sockaddr_in sin;
|
179
|
-
|
180
|
-
memset (& sin, 0, sizeof (struct sockaddr_in));
|
181
|
-
|
182
|
-
sin.sin_family = AF_INET;
|
183
|
-
sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
|
184
|
-
sin.sin_addr.s_addr = address -> host;
|
185
|
-
|
186
|
-
return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in)) == SOCKET_ERROR ? -1 : 0;
|
187
|
-
}
|
188
|
-
|
189
|
-
ENetSocket
|
190
|
-
enet_socket_accept (ENetSocket socket, ENetAddress * address)
|
191
|
-
{
|
192
|
-
SOCKET result;
|
193
|
-
struct sockaddr_in sin;
|
194
|
-
int sinLength = sizeof (struct sockaddr_in);
|
195
|
-
|
196
|
-
result = accept (socket,
|
197
|
-
address != NULL ? (struct sockaddr *) & sin : NULL,
|
198
|
-
address != NULL ? & sinLength : NULL);
|
199
|
-
|
200
|
-
if (result == INVALID_SOCKET)
|
201
|
-
return ENET_SOCKET_NULL;
|
202
|
-
|
203
|
-
if (address != NULL)
|
204
|
-
{
|
205
|
-
address -> host = (enet_uint32) sin.sin_addr.s_addr;
|
206
|
-
address -> port = ENET_NET_TO_HOST_16 (sin.sin_port);
|
207
|
-
}
|
208
|
-
|
209
|
-
return result;
|
210
|
-
}
|
211
|
-
|
212
|
-
void
|
213
|
-
enet_socket_destroy (ENetSocket socket)
|
214
|
-
{
|
215
|
-
closesocket (socket);
|
216
|
-
}
|
217
|
-
|
218
|
-
int
|
219
|
-
enet_socket_send (ENetSocket socket,
|
220
|
-
const ENetAddress * address,
|
221
|
-
const ENetBuffer * buffers,
|
222
|
-
size_t bufferCount)
|
223
|
-
{
|
224
|
-
struct sockaddr_in sin;
|
225
|
-
DWORD sentLength;
|
226
|
-
|
227
|
-
if (address != NULL)
|
228
|
-
{
|
229
|
-
memset (& sin, 0, sizeof (struct sockaddr_in));
|
230
|
-
|
231
|
-
sin.sin_family = AF_INET;
|
232
|
-
sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
|
233
|
-
sin.sin_addr.s_addr = address -> host;
|
234
|
-
}
|
235
|
-
|
236
|
-
if (WSASendTo (socket,
|
237
|
-
(LPWSABUF) buffers,
|
238
|
-
(DWORD) bufferCount,
|
239
|
-
& sentLength,
|
240
|
-
0,
|
241
|
-
address != NULL ? (struct sockaddr *) & sin : 0,
|
242
|
-
address != NULL ? sizeof (struct sockaddr_in) : 0,
|
243
|
-
NULL,
|
244
|
-
NULL) == SOCKET_ERROR)
|
245
|
-
{
|
246
|
-
if (WSAGetLastError () == WSAEWOULDBLOCK)
|
247
|
-
return 0;
|
248
|
-
|
249
|
-
return -1;
|
250
|
-
}
|
251
|
-
|
252
|
-
return (int) sentLength;
|
253
|
-
}
|
254
|
-
|
255
|
-
int
|
256
|
-
enet_socket_receive (ENetSocket socket,
|
257
|
-
ENetAddress * address,
|
258
|
-
ENetBuffer * buffers,
|
259
|
-
size_t bufferCount)
|
260
|
-
{
|
261
|
-
INT sinLength = sizeof (struct sockaddr_in);
|
262
|
-
DWORD flags = 0,
|
263
|
-
recvLength;
|
264
|
-
struct sockaddr_in sin;
|
265
|
-
|
266
|
-
if (WSARecvFrom (socket,
|
267
|
-
(LPWSABUF) buffers,
|
268
|
-
(DWORD) bufferCount,
|
269
|
-
& recvLength,
|
270
|
-
& flags,
|
271
|
-
address != NULL ? (struct sockaddr *) & sin : NULL,
|
272
|
-
address != NULL ? & sinLength : NULL,
|
273
|
-
NULL,
|
274
|
-
NULL) == SOCKET_ERROR)
|
275
|
-
{
|
276
|
-
switch (WSAGetLastError ())
|
277
|
-
{
|
278
|
-
case WSAEWOULDBLOCK:
|
279
|
-
case WSAECONNRESET:
|
280
|
-
return 0;
|
281
|
-
}
|
282
|
-
|
283
|
-
return -1;
|
284
|
-
}
|
285
|
-
|
286
|
-
if (flags & MSG_PARTIAL)
|
287
|
-
return -1;
|
288
|
-
|
289
|
-
if (address != NULL)
|
290
|
-
{
|
291
|
-
address -> host = (enet_uint32) sin.sin_addr.s_addr;
|
292
|
-
address -> port = ENET_NET_TO_HOST_16 (sin.sin_port);
|
293
|
-
}
|
294
|
-
|
295
|
-
return (int) recvLength;
|
296
|
-
}
|
297
|
-
|
298
|
-
int
|
299
|
-
enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocketSet * writeSet, enet_uint32 timeout)
|
300
|
-
{
|
301
|
-
struct timeval timeVal;
|
302
|
-
|
303
|
-
timeVal.tv_sec = timeout / 1000;
|
304
|
-
timeVal.tv_usec = (timeout % 1000) * 1000;
|
305
|
-
|
306
|
-
return select (maxSocket + 1, readSet, writeSet, NULL, & timeVal);
|
307
|
-
}
|
308
|
-
|
309
|
-
int
|
310
|
-
enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeout)
|
311
|
-
{
|
312
|
-
fd_set readSet, writeSet;
|
313
|
-
struct timeval timeVal;
|
314
|
-
int selectCount;
|
315
|
-
|
316
|
-
timeVal.tv_sec = timeout / 1000;
|
317
|
-
timeVal.tv_usec = (timeout % 1000) * 1000;
|
318
|
-
|
319
|
-
FD_ZERO (& readSet);
|
320
|
-
FD_ZERO (& writeSet);
|
321
|
-
|
322
|
-
if (* condition & ENET_SOCKET_WAIT_SEND)
|
323
|
-
FD_SET (socket, & writeSet);
|
324
|
-
|
325
|
-
if (* condition & ENET_SOCKET_WAIT_RECEIVE)
|
326
|
-
FD_SET (socket, & readSet);
|
327
|
-
|
328
|
-
selectCount = select (socket + 1, & readSet, & writeSet, NULL, & timeVal);
|
329
|
-
|
330
|
-
if (selectCount < 0)
|
331
|
-
return -1;
|
332
|
-
|
333
|
-
* condition = ENET_SOCKET_WAIT_NONE;
|
334
|
-
|
335
|
-
if (selectCount == 0)
|
336
|
-
return 0;
|
337
|
-
|
338
|
-
if (FD_ISSET (socket, & writeSet))
|
339
|
-
* condition |= ENET_SOCKET_WAIT_SEND;
|
340
|
-
|
341
|
-
if (FD_ISSET (socket, & readSet))
|
342
|
-
* condition |= ENET_SOCKET_WAIT_RECEIVE;
|
343
|
-
|
344
|
-
return 0;
|
345
|
-
}
|
346
|
-
|
347
|
-
#endif
|
348
|
-
|
data/ext/renet/win32.h
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
@file win32.h
|
3
|
-
@brief ENet Win32 header
|
4
|
-
*/
|
5
|
-
#ifndef __ENET_WIN32_H__
|
6
|
-
#define __ENET_WIN32_H__
|
7
|
-
|
8
|
-
#ifdef ENET_BUILDING_LIB
|
9
|
-
#pragma warning (disable: 4996) // 'strncpy' was declared deprecated
|
10
|
-
#pragma warning (disable: 4267) // size_t to int conversion
|
11
|
-
#pragma warning (disable: 4244) // 64bit to 32bit int
|
12
|
-
#pragma warning (disable: 4018) // signed/unsigned mismatch
|
13
|
-
#endif
|
14
|
-
|
15
|
-
#include <stdlib.h>
|
16
|
-
#include <winsock2.h>
|
17
|
-
|
18
|
-
typedef SOCKET ENetSocket;
|
19
|
-
|
20
|
-
enum
|
21
|
-
{
|
22
|
-
ENET_SOCKET_NULL = INVALID_SOCKET
|
23
|
-
};
|
24
|
-
|
25
|
-
#define ENET_HOST_TO_NET_16(value) (htons (value))
|
26
|
-
#define ENET_HOST_TO_NET_32(value) (htonl (value))
|
27
|
-
|
28
|
-
#define ENET_NET_TO_HOST_16(value) (ntohs (value))
|
29
|
-
#define ENET_NET_TO_HOST_32(value) (ntohl (value))
|
30
|
-
|
31
|
-
typedef struct
|
32
|
-
{
|
33
|
-
size_t dataLength;
|
34
|
-
void * data;
|
35
|
-
} ENetBuffer;
|
36
|
-
|
37
|
-
#define ENET_CALLBACK __cdecl
|
38
|
-
|
39
|
-
#if defined ENET_DLL
|
40
|
-
#if defined ENET_BUILDING_LIB
|
41
|
-
#define ENET_API __declspec( dllexport )
|
42
|
-
#else
|
43
|
-
#define ENET_API __declspec( dllimport )
|
44
|
-
#endif /* ENET_BUILDING_LIB */
|
45
|
-
#else /* !ENET_DLL */
|
46
|
-
#define ENET_API extern
|
47
|
-
#endif /* ENET_DLL */
|
48
|
-
|
49
|
-
typedef fd_set ENetSocketSet;
|
50
|
-
|
51
|
-
#define ENET_SOCKETSET_EMPTY(sockset) FD_ZERO (& (sockset))
|
52
|
-
#define ENET_SOCKETSET_ADD(sockset, socket) FD_SET (socket, & (sockset))
|
53
|
-
#define ENET_SOCKETSET_REMOVE(sockset, socket) FD_CLEAR (socket, & (sockset))
|
54
|
-
#define ENET_SOCKETSET_CHECK(sockset, socket) FD_ISSET (socket, & (sockset))
|
55
|
-
|
56
|
-
#endif /* __ENET_WIN32_H__ */
|
57
|
-
|
58
|
-
|