renet 0.1.12-universal-darwin → 0.1.13-universal-darwin
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/protocol.h
DELETED
@@ -1,196 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
@file protocol.h
|
3
|
-
@brief ENet protocol
|
4
|
-
*/
|
5
|
-
#ifndef __ENET_PROTOCOL_H__
|
6
|
-
#define __ENET_PROTOCOL_H__
|
7
|
-
|
8
|
-
#include "types.h"
|
9
|
-
|
10
|
-
enum
|
11
|
-
{
|
12
|
-
ENET_PROTOCOL_MINIMUM_MTU = 576,
|
13
|
-
ENET_PROTOCOL_MAXIMUM_MTU = 4096,
|
14
|
-
ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS = 32,
|
15
|
-
ENET_PROTOCOL_MINIMUM_WINDOW_SIZE = 4096,
|
16
|
-
ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE = 32768,
|
17
|
-
ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT = 1,
|
18
|
-
ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255,
|
19
|
-
ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xFFF
|
20
|
-
};
|
21
|
-
|
22
|
-
typedef enum _ENetProtocolCommand
|
23
|
-
{
|
24
|
-
ENET_PROTOCOL_COMMAND_NONE = 0,
|
25
|
-
ENET_PROTOCOL_COMMAND_ACKNOWLEDGE = 1,
|
26
|
-
ENET_PROTOCOL_COMMAND_CONNECT = 2,
|
27
|
-
ENET_PROTOCOL_COMMAND_VERIFY_CONNECT = 3,
|
28
|
-
ENET_PROTOCOL_COMMAND_DISCONNECT = 4,
|
29
|
-
ENET_PROTOCOL_COMMAND_PING = 5,
|
30
|
-
ENET_PROTOCOL_COMMAND_SEND_RELIABLE = 6,
|
31
|
-
ENET_PROTOCOL_COMMAND_SEND_UNRELIABLE = 7,
|
32
|
-
ENET_PROTOCOL_COMMAND_SEND_FRAGMENT = 8,
|
33
|
-
ENET_PROTOCOL_COMMAND_SEND_UNSEQUENCED = 9,
|
34
|
-
ENET_PROTOCOL_COMMAND_BANDWIDTH_LIMIT = 10,
|
35
|
-
ENET_PROTOCOL_COMMAND_THROTTLE_CONFIGURE = 11,
|
36
|
-
ENET_PROTOCOL_COMMAND_COUNT = 12,
|
37
|
-
|
38
|
-
ENET_PROTOCOL_COMMAND_MASK = 0x0F
|
39
|
-
} ENetProtocolCommand;
|
40
|
-
|
41
|
-
typedef enum _ENetProtocolFlag
|
42
|
-
{
|
43
|
-
ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE = (1 << 7),
|
44
|
-
ENET_PROTOCOL_COMMAND_FLAG_UNSEQUENCED = (1 << 6),
|
45
|
-
|
46
|
-
ENET_PROTOCOL_HEADER_FLAG_COMPRESSED = (1 << 14),
|
47
|
-
ENET_PROTOCOL_HEADER_FLAG_SENT_TIME = (1 << 15),
|
48
|
-
ENET_PROTOCOL_HEADER_FLAG_MASK = ENET_PROTOCOL_HEADER_FLAG_COMPRESSED | ENET_PROTOCOL_HEADER_FLAG_SENT_TIME,
|
49
|
-
|
50
|
-
ENET_PROTOCOL_HEADER_SESSION_MASK = (3 << 12),
|
51
|
-
ENET_PROTOCOL_HEADER_SESSION_SHIFT = 12
|
52
|
-
} ENetProtocolFlag;
|
53
|
-
|
54
|
-
#ifdef _MSC_VER_
|
55
|
-
#pragma pack(push, 1)
|
56
|
-
#define ENET_PACKED
|
57
|
-
#elif defined(__GNUC__)
|
58
|
-
#define ENET_PACKED __attribute__ ((packed))
|
59
|
-
#else
|
60
|
-
#define ENET_PACKED
|
61
|
-
#endif
|
62
|
-
|
63
|
-
typedef struct _ENetProtocolHeader
|
64
|
-
{
|
65
|
-
enet_uint16 peerID;
|
66
|
-
enet_uint16 sentTime;
|
67
|
-
} ENET_PACKED ENetProtocolHeader;
|
68
|
-
|
69
|
-
typedef struct _ENetProtocolCommandHeader
|
70
|
-
{
|
71
|
-
enet_uint8 command;
|
72
|
-
enet_uint8 channelID;
|
73
|
-
enet_uint16 reliableSequenceNumber;
|
74
|
-
} ENET_PACKED ENetProtocolCommandHeader;
|
75
|
-
|
76
|
-
typedef struct _ENetProtocolAcknowledge
|
77
|
-
{
|
78
|
-
ENetProtocolCommandHeader header;
|
79
|
-
enet_uint16 receivedReliableSequenceNumber;
|
80
|
-
enet_uint16 receivedSentTime;
|
81
|
-
} ENET_PACKED ENetProtocolAcknowledge;
|
82
|
-
|
83
|
-
typedef struct _ENetProtocolConnect
|
84
|
-
{
|
85
|
-
ENetProtocolCommandHeader header;
|
86
|
-
enet_uint16 outgoingPeerID;
|
87
|
-
enet_uint8 incomingSessionID;
|
88
|
-
enet_uint8 outgoingSessionID;
|
89
|
-
enet_uint32 mtu;
|
90
|
-
enet_uint32 windowSize;
|
91
|
-
enet_uint32 channelCount;
|
92
|
-
enet_uint32 incomingBandwidth;
|
93
|
-
enet_uint32 outgoingBandwidth;
|
94
|
-
enet_uint32 packetThrottleInterval;
|
95
|
-
enet_uint32 packetThrottleAcceleration;
|
96
|
-
enet_uint32 packetThrottleDeceleration;
|
97
|
-
enet_uint32 connectID;
|
98
|
-
enet_uint32 data;
|
99
|
-
} ENET_PACKED ENetProtocolConnect;
|
100
|
-
|
101
|
-
typedef struct _ENetProtocolVerifyConnect
|
102
|
-
{
|
103
|
-
ENetProtocolCommandHeader header;
|
104
|
-
enet_uint16 outgoingPeerID;
|
105
|
-
enet_uint8 incomingSessionID;
|
106
|
-
enet_uint8 outgoingSessionID;
|
107
|
-
enet_uint32 mtu;
|
108
|
-
enet_uint32 windowSize;
|
109
|
-
enet_uint32 channelCount;
|
110
|
-
enet_uint32 incomingBandwidth;
|
111
|
-
enet_uint32 outgoingBandwidth;
|
112
|
-
enet_uint32 packetThrottleInterval;
|
113
|
-
enet_uint32 packetThrottleAcceleration;
|
114
|
-
enet_uint32 packetThrottleDeceleration;
|
115
|
-
enet_uint32 connectID;
|
116
|
-
} ENET_PACKED ENetProtocolVerifyConnect;
|
117
|
-
|
118
|
-
typedef struct _ENetProtocolBandwidthLimit
|
119
|
-
{
|
120
|
-
ENetProtocolCommandHeader header;
|
121
|
-
enet_uint32 incomingBandwidth;
|
122
|
-
enet_uint32 outgoingBandwidth;
|
123
|
-
} ENET_PACKED ENetProtocolBandwidthLimit;
|
124
|
-
|
125
|
-
typedef struct _ENetProtocolThrottleConfigure
|
126
|
-
{
|
127
|
-
ENetProtocolCommandHeader header;
|
128
|
-
enet_uint32 packetThrottleInterval;
|
129
|
-
enet_uint32 packetThrottleAcceleration;
|
130
|
-
enet_uint32 packetThrottleDeceleration;
|
131
|
-
} ENET_PACKED ENetProtocolThrottleConfigure;
|
132
|
-
|
133
|
-
typedef struct _ENetProtocolDisconnect
|
134
|
-
{
|
135
|
-
ENetProtocolCommandHeader header;
|
136
|
-
enet_uint32 data;
|
137
|
-
} ENET_PACKED ENetProtocolDisconnect;
|
138
|
-
|
139
|
-
typedef struct _ENetProtocolPing
|
140
|
-
{
|
141
|
-
ENetProtocolCommandHeader header;
|
142
|
-
} ENET_PACKED ENetProtocolPing;
|
143
|
-
|
144
|
-
typedef struct _ENetProtocolSendReliable
|
145
|
-
{
|
146
|
-
ENetProtocolCommandHeader header;
|
147
|
-
enet_uint16 dataLength;
|
148
|
-
} ENET_PACKED ENetProtocolSendReliable;
|
149
|
-
|
150
|
-
typedef struct _ENetProtocolSendUnreliable
|
151
|
-
{
|
152
|
-
ENetProtocolCommandHeader header;
|
153
|
-
enet_uint16 unreliableSequenceNumber;
|
154
|
-
enet_uint16 dataLength;
|
155
|
-
} ENET_PACKED ENetProtocolSendUnreliable;
|
156
|
-
|
157
|
-
typedef struct _ENetProtocolSendUnsequenced
|
158
|
-
{
|
159
|
-
ENetProtocolCommandHeader header;
|
160
|
-
enet_uint16 unsequencedGroup;
|
161
|
-
enet_uint16 dataLength;
|
162
|
-
} ENET_PACKED ENetProtocolSendUnsequenced;
|
163
|
-
|
164
|
-
typedef struct _ENetProtocolSendFragment
|
165
|
-
{
|
166
|
-
ENetProtocolCommandHeader header;
|
167
|
-
enet_uint16 startSequenceNumber;
|
168
|
-
enet_uint16 dataLength;
|
169
|
-
enet_uint32 fragmentCount;
|
170
|
-
enet_uint32 fragmentNumber;
|
171
|
-
enet_uint32 totalLength;
|
172
|
-
enet_uint32 fragmentOffset;
|
173
|
-
} ENET_PACKED ENetProtocolSendFragment;
|
174
|
-
|
175
|
-
typedef union _ENetProtocol
|
176
|
-
{
|
177
|
-
ENetProtocolCommandHeader header;
|
178
|
-
ENetProtocolAcknowledge acknowledge;
|
179
|
-
ENetProtocolConnect connect;
|
180
|
-
ENetProtocolVerifyConnect verifyConnect;
|
181
|
-
ENetProtocolDisconnect disconnect;
|
182
|
-
ENetProtocolPing ping;
|
183
|
-
ENetProtocolSendReliable sendReliable;
|
184
|
-
ENetProtocolSendUnreliable sendUnreliable;
|
185
|
-
ENetProtocolSendUnsequenced sendUnsequenced;
|
186
|
-
ENetProtocolSendFragment sendFragment;
|
187
|
-
ENetProtocolBandwidthLimit bandwidthLimit;
|
188
|
-
ENetProtocolThrottleConfigure throttleConfigure;
|
189
|
-
} ENET_PACKED ENetProtocol;
|
190
|
-
|
191
|
-
#ifdef _MSC_VER_
|
192
|
-
#pragma pack(pop)
|
193
|
-
#endif
|
194
|
-
|
195
|
-
#endif /* __ENET_PROTOCOL_H__ */
|
196
|
-
|
data/ext/renet/time.h
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
@file time.h
|
3
|
-
@brief ENet time constants and macros
|
4
|
-
*/
|
5
|
-
#ifndef __ENET_TIME_H__
|
6
|
-
#define __ENET_TIME_H__
|
7
|
-
|
8
|
-
#define ENET_TIME_OVERFLOW 86400000
|
9
|
-
|
10
|
-
#define ENET_TIME_LESS(a, b) ((a) - (b) >= ENET_TIME_OVERFLOW)
|
11
|
-
#define ENET_TIME_GREATER(a, b) ((b) - (a) >= ENET_TIME_OVERFLOW)
|
12
|
-
#define ENET_TIME_LESS_EQUAL(a, b) (! ENET_TIME_GREATER (a, b))
|
13
|
-
#define ENET_TIME_GREATER_EQUAL(a, b) (! ENET_TIME_LESS (a, b))
|
14
|
-
|
15
|
-
#define ENET_TIME_DIFFERENCE(a, b) ((a) - (b) >= ENET_TIME_OVERFLOW ? (b) - (a) : (a) - (b))
|
16
|
-
|
17
|
-
#endif /* __ENET_TIME_H__ */
|
18
|
-
|
data/ext/renet/types.h
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
@file types.h
|
3
|
-
@brief type definitions for ENet
|
4
|
-
*/
|
5
|
-
#ifndef __ENET_TYPES_H__
|
6
|
-
#define __ENET_TYPES_H__
|
7
|
-
|
8
|
-
typedef unsigned char enet_uint8; /**< unsigned 8-bit type */
|
9
|
-
typedef unsigned short enet_uint16; /**< unsigned 16-bit type */
|
10
|
-
typedef unsigned int enet_uint32; /**< unsigned 32-bit type */
|
11
|
-
|
12
|
-
#endif /* __ENET_TYPES_H__ */
|
13
|
-
|
data/ext/renet/unix.c
DELETED
@@ -1,446 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
@file unix.c
|
3
|
-
@brief ENet Unix system specific functions
|
4
|
-
*/
|
5
|
-
#ifndef WIN32
|
6
|
-
|
7
|
-
#include <sys/types.h>
|
8
|
-
#include <sys/socket.h>
|
9
|
-
#include <sys/ioctl.h>
|
10
|
-
#include <sys/time.h>
|
11
|
-
#include <arpa/inet.h>
|
12
|
-
#include <netdb.h>
|
13
|
-
#include <unistd.h>
|
14
|
-
#include <string.h>
|
15
|
-
#include <errno.h>
|
16
|
-
#include <time.h>
|
17
|
-
|
18
|
-
#define ENET_BUILDING_LIB 1
|
19
|
-
#include "enet.h"
|
20
|
-
|
21
|
-
#ifdef HAS_FCNTL
|
22
|
-
#include <fcntl.h>
|
23
|
-
#endif
|
24
|
-
|
25
|
-
#ifdef __APPLE__
|
26
|
-
#undef HAS_POLL
|
27
|
-
#endif
|
28
|
-
|
29
|
-
#ifdef HAS_POLL
|
30
|
-
#include <sys/poll.h>
|
31
|
-
#endif
|
32
|
-
|
33
|
-
#ifdef __APPLE__
|
34
|
-
#ifndef _SOCKLEN_T
|
35
|
-
typedef int socklen_t;
|
36
|
-
#endif
|
37
|
-
#endif
|
38
|
-
|
39
|
-
#ifdef __GNUC__
|
40
|
-
#ifndef __socklen_t_defined
|
41
|
-
typedef int socklen_t;
|
42
|
-
#endif
|
43
|
-
#endif
|
44
|
-
|
45
|
-
#ifndef MSG_NOSIGNAL
|
46
|
-
#define MSG_NOSIGNAL 0
|
47
|
-
#endif
|
48
|
-
|
49
|
-
static enet_uint32 timeBase = 0;
|
50
|
-
|
51
|
-
int
|
52
|
-
enet_initialize (void)
|
53
|
-
{
|
54
|
-
return 0;
|
55
|
-
}
|
56
|
-
|
57
|
-
void
|
58
|
-
enet_deinitialize (void)
|
59
|
-
{
|
60
|
-
}
|
61
|
-
|
62
|
-
enet_uint32
|
63
|
-
enet_time_get (void)
|
64
|
-
{
|
65
|
-
struct timeval timeVal;
|
66
|
-
|
67
|
-
gettimeofday (& timeVal, NULL);
|
68
|
-
|
69
|
-
return timeVal.tv_sec * 1000 + timeVal.tv_usec / 1000 - timeBase;
|
70
|
-
}
|
71
|
-
|
72
|
-
void
|
73
|
-
enet_time_set (enet_uint32 newTimeBase)
|
74
|
-
{
|
75
|
-
struct timeval timeVal;
|
76
|
-
|
77
|
-
gettimeofday (& timeVal, NULL);
|
78
|
-
|
79
|
-
timeBase = timeVal.tv_sec * 1000 + timeVal.tv_usec / 1000 - newTimeBase;
|
80
|
-
}
|
81
|
-
|
82
|
-
int
|
83
|
-
enet_address_set_host (ENetAddress * address, const char * name)
|
84
|
-
{
|
85
|
-
struct hostent * hostEntry = NULL;
|
86
|
-
#ifdef HAS_GETHOSTBYNAME_R
|
87
|
-
struct hostent hostData;
|
88
|
-
char buffer [2048];
|
89
|
-
int errnum;
|
90
|
-
|
91
|
-
#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
92
|
-
gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum);
|
93
|
-
#else
|
94
|
-
hostEntry = gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & errnum);
|
95
|
-
#endif
|
96
|
-
#else
|
97
|
-
hostEntry = gethostbyname (name);
|
98
|
-
#endif
|
99
|
-
|
100
|
-
if (hostEntry == NULL ||
|
101
|
-
hostEntry -> h_addrtype != AF_INET)
|
102
|
-
{
|
103
|
-
#ifdef HAS_INET_PTON
|
104
|
-
if (! inet_pton (AF_INET, name, & address -> host))
|
105
|
-
#else
|
106
|
-
if (! inet_aton (name, (struct in_addr *) & address -> host))
|
107
|
-
#endif
|
108
|
-
return -1;
|
109
|
-
return 0;
|
110
|
-
}
|
111
|
-
|
112
|
-
address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0];
|
113
|
-
|
114
|
-
return 0;
|
115
|
-
}
|
116
|
-
|
117
|
-
int
|
118
|
-
enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength)
|
119
|
-
{
|
120
|
-
#ifdef HAS_INET_NTOP
|
121
|
-
if (inet_ntop (AF_INET, & address -> host, name, nameLength) == NULL)
|
122
|
-
#else
|
123
|
-
char * addr = inet_ntoa (* (struct in_addr *) & address -> host);
|
124
|
-
if (addr != NULL)
|
125
|
-
strncpy (name, addr, nameLength);
|
126
|
-
else
|
127
|
-
#endif
|
128
|
-
return -1;
|
129
|
-
return 0;
|
130
|
-
}
|
131
|
-
|
132
|
-
int
|
133
|
-
enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength)
|
134
|
-
{
|
135
|
-
struct in_addr in;
|
136
|
-
struct hostent * hostEntry = NULL;
|
137
|
-
#ifdef HAS_GETHOSTBYADDR_R
|
138
|
-
struct hostent hostData;
|
139
|
-
char buffer [2048];
|
140
|
-
int errnum;
|
141
|
-
|
142
|
-
in.s_addr = address -> host;
|
143
|
-
|
144
|
-
#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
145
|
-
gethostbyaddr_r ((char *) & in, sizeof (struct in_addr), AF_INET, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum);
|
146
|
-
#else
|
147
|
-
hostEntry = gethostbyaddr_r ((char *) & in, sizeof (struct in_addr), AF_INET, & hostData, buffer, sizeof (buffer), & errnum);
|
148
|
-
#endif
|
149
|
-
#else
|
150
|
-
in.s_addr = address -> host;
|
151
|
-
|
152
|
-
hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET);
|
153
|
-
#endif
|
154
|
-
|
155
|
-
if (hostEntry == NULL)
|
156
|
-
return enet_address_get_host_ip (address, name, nameLength);
|
157
|
-
|
158
|
-
strncpy (name, hostEntry -> h_name, nameLength);
|
159
|
-
|
160
|
-
return 0;
|
161
|
-
}
|
162
|
-
|
163
|
-
int
|
164
|
-
enet_socket_bind (ENetSocket socket, const ENetAddress * address)
|
165
|
-
{
|
166
|
-
struct sockaddr_in sin;
|
167
|
-
|
168
|
-
memset (& sin, 0, sizeof (struct sockaddr_in));
|
169
|
-
|
170
|
-
sin.sin_family = AF_INET;
|
171
|
-
|
172
|
-
if (address != NULL)
|
173
|
-
{
|
174
|
-
sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
|
175
|
-
sin.sin_addr.s_addr = address -> host;
|
176
|
-
}
|
177
|
-
else
|
178
|
-
{
|
179
|
-
sin.sin_port = 0;
|
180
|
-
sin.sin_addr.s_addr = INADDR_ANY;
|
181
|
-
}
|
182
|
-
|
183
|
-
return bind (socket,
|
184
|
-
(struct sockaddr *) & sin,
|
185
|
-
sizeof (struct sockaddr_in));
|
186
|
-
}
|
187
|
-
|
188
|
-
int
|
189
|
-
enet_socket_listen (ENetSocket socket, int backlog)
|
190
|
-
{
|
191
|
-
return listen (socket, backlog < 0 ? SOMAXCONN : backlog);
|
192
|
-
}
|
193
|
-
|
194
|
-
ENetSocket
|
195
|
-
enet_socket_create (ENetSocketType type)
|
196
|
-
{
|
197
|
-
return socket (PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);
|
198
|
-
}
|
199
|
-
|
200
|
-
int
|
201
|
-
enet_socket_set_option (ENetSocket socket, ENetSocketOption option, int value)
|
202
|
-
{
|
203
|
-
int result = -1;
|
204
|
-
switch (option)
|
205
|
-
{
|
206
|
-
case ENET_SOCKOPT_NONBLOCK:
|
207
|
-
#ifdef HAS_FCNTL
|
208
|
-
result = fcntl (socket, F_SETFL, O_NONBLOCK | fcntl (socket, F_GETFL));
|
209
|
-
#else
|
210
|
-
result = ioctl (socket, FIONBIO, & value);
|
211
|
-
#endif
|
212
|
-
break;
|
213
|
-
|
214
|
-
case ENET_SOCKOPT_BROADCAST:
|
215
|
-
result = setsockopt (socket, SOL_SOCKET, SO_BROADCAST, (char *) & value, sizeof (int));
|
216
|
-
break;
|
217
|
-
|
218
|
-
case ENET_SOCKOPT_REUSEADDR:
|
219
|
-
result = setsockopt (socket, SOL_SOCKET, SO_REUSEADDR, (char *) & value, sizeof (int));
|
220
|
-
break;
|
221
|
-
|
222
|
-
case ENET_SOCKOPT_RCVBUF:
|
223
|
-
result = setsockopt (socket, SOL_SOCKET, SO_RCVBUF, (char *) & value, sizeof (int));
|
224
|
-
break;
|
225
|
-
|
226
|
-
case ENET_SOCKOPT_SNDBUF:
|
227
|
-
result = setsockopt (socket, SOL_SOCKET, SO_SNDBUF, (char *) & value, sizeof (int));
|
228
|
-
break;
|
229
|
-
|
230
|
-
default:
|
231
|
-
break;
|
232
|
-
}
|
233
|
-
return result == -1 ? -1 : 0;
|
234
|
-
}
|
235
|
-
|
236
|
-
int
|
237
|
-
enet_socket_connect (ENetSocket socket, const ENetAddress * address)
|
238
|
-
{
|
239
|
-
struct sockaddr_in sin;
|
240
|
-
|
241
|
-
memset (& sin, 0, sizeof (struct sockaddr_in));
|
242
|
-
|
243
|
-
sin.sin_family = AF_INET;
|
244
|
-
sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
|
245
|
-
sin.sin_addr.s_addr = address -> host;
|
246
|
-
|
247
|
-
return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in));
|
248
|
-
}
|
249
|
-
|
250
|
-
ENetSocket
|
251
|
-
enet_socket_accept (ENetSocket socket, ENetAddress * address)
|
252
|
-
{
|
253
|
-
int result;
|
254
|
-
struct sockaddr_in sin;
|
255
|
-
socklen_t sinLength = sizeof (struct sockaddr_in);
|
256
|
-
|
257
|
-
result = accept (socket,
|
258
|
-
address != NULL ? (struct sockaddr *) & sin : NULL,
|
259
|
-
address != NULL ? & sinLength : NULL);
|
260
|
-
|
261
|
-
if (result == -1)
|
262
|
-
return ENET_SOCKET_NULL;
|
263
|
-
|
264
|
-
if (address != NULL)
|
265
|
-
{
|
266
|
-
address -> host = (enet_uint32) sin.sin_addr.s_addr;
|
267
|
-
address -> port = ENET_NET_TO_HOST_16 (sin.sin_port);
|
268
|
-
}
|
269
|
-
|
270
|
-
return result;
|
271
|
-
}
|
272
|
-
|
273
|
-
void
|
274
|
-
enet_socket_destroy (ENetSocket socket)
|
275
|
-
{
|
276
|
-
close (socket);
|
277
|
-
}
|
278
|
-
|
279
|
-
int
|
280
|
-
enet_socket_send (ENetSocket socket,
|
281
|
-
const ENetAddress * address,
|
282
|
-
const ENetBuffer * buffers,
|
283
|
-
size_t bufferCount)
|
284
|
-
{
|
285
|
-
struct msghdr msgHdr;
|
286
|
-
struct sockaddr_in sin;
|
287
|
-
int sentLength;
|
288
|
-
|
289
|
-
memset (& msgHdr, 0, sizeof (struct msghdr));
|
290
|
-
|
291
|
-
if (address != NULL)
|
292
|
-
{
|
293
|
-
memset (& sin, 0, sizeof (struct sockaddr_in));
|
294
|
-
|
295
|
-
sin.sin_family = AF_INET;
|
296
|
-
sin.sin_port = ENET_HOST_TO_NET_16 (address -> port);
|
297
|
-
sin.sin_addr.s_addr = address -> host;
|
298
|
-
|
299
|
-
msgHdr.msg_name = & sin;
|
300
|
-
msgHdr.msg_namelen = sizeof (struct sockaddr_in);
|
301
|
-
}
|
302
|
-
|
303
|
-
msgHdr.msg_iov = (struct iovec *) buffers;
|
304
|
-
msgHdr.msg_iovlen = bufferCount;
|
305
|
-
|
306
|
-
sentLength = sendmsg (socket, & msgHdr, MSG_NOSIGNAL);
|
307
|
-
|
308
|
-
if (sentLength == -1)
|
309
|
-
{
|
310
|
-
if (errno == EWOULDBLOCK)
|
311
|
-
return 0;
|
312
|
-
|
313
|
-
return -1;
|
314
|
-
}
|
315
|
-
|
316
|
-
return sentLength;
|
317
|
-
}
|
318
|
-
|
319
|
-
int
|
320
|
-
enet_socket_receive (ENetSocket socket,
|
321
|
-
ENetAddress * address,
|
322
|
-
ENetBuffer * buffers,
|
323
|
-
size_t bufferCount)
|
324
|
-
{
|
325
|
-
struct msghdr msgHdr;
|
326
|
-
struct sockaddr_in sin;
|
327
|
-
int recvLength;
|
328
|
-
|
329
|
-
memset (& msgHdr, 0, sizeof (struct msghdr));
|
330
|
-
|
331
|
-
if (address != NULL)
|
332
|
-
{
|
333
|
-
msgHdr.msg_name = & sin;
|
334
|
-
msgHdr.msg_namelen = sizeof (struct sockaddr_in);
|
335
|
-
}
|
336
|
-
|
337
|
-
msgHdr.msg_iov = (struct iovec *) buffers;
|
338
|
-
msgHdr.msg_iovlen = bufferCount;
|
339
|
-
|
340
|
-
recvLength = recvmsg (socket, & msgHdr, MSG_NOSIGNAL);
|
341
|
-
|
342
|
-
if (recvLength == -1)
|
343
|
-
{
|
344
|
-
if (errno == EWOULDBLOCK)
|
345
|
-
return 0;
|
346
|
-
|
347
|
-
return -1;
|
348
|
-
}
|
349
|
-
|
350
|
-
#ifdef HAS_MSGHDR_FLAGS
|
351
|
-
if (msgHdr.msg_flags & MSG_TRUNC)
|
352
|
-
return -1;
|
353
|
-
#endif
|
354
|
-
|
355
|
-
if (address != NULL)
|
356
|
-
{
|
357
|
-
address -> host = (enet_uint32) sin.sin_addr.s_addr;
|
358
|
-
address -> port = ENET_NET_TO_HOST_16 (sin.sin_port);
|
359
|
-
}
|
360
|
-
|
361
|
-
return recvLength;
|
362
|
-
}
|
363
|
-
|
364
|
-
int
|
365
|
-
enet_socketset_select (ENetSocket maxSocket, ENetSocketSet * readSet, ENetSocketSet * writeSet, enet_uint32 timeout)
|
366
|
-
{
|
367
|
-
struct timeval timeVal;
|
368
|
-
|
369
|
-
timeVal.tv_sec = timeout / 1000;
|
370
|
-
timeVal.tv_usec = (timeout % 1000) * 1000;
|
371
|
-
|
372
|
-
return select (maxSocket + 1, readSet, writeSet, NULL, & timeVal);
|
373
|
-
}
|
374
|
-
|
375
|
-
int
|
376
|
-
enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeout)
|
377
|
-
{
|
378
|
-
#ifdef HAS_POLL
|
379
|
-
struct pollfd pollSocket;
|
380
|
-
int pollCount;
|
381
|
-
|
382
|
-
pollSocket.fd = socket;
|
383
|
-
pollSocket.events = 0;
|
384
|
-
|
385
|
-
if (* condition & ENET_SOCKET_WAIT_SEND)
|
386
|
-
pollSocket.events |= POLLOUT;
|
387
|
-
|
388
|
-
if (* condition & ENET_SOCKET_WAIT_RECEIVE)
|
389
|
-
pollSocket.events |= POLLIN;
|
390
|
-
|
391
|
-
pollCount = poll (& pollSocket, 1, timeout);
|
392
|
-
|
393
|
-
if (pollCount < 0)
|
394
|
-
return -1;
|
395
|
-
|
396
|
-
* condition = ENET_SOCKET_WAIT_NONE;
|
397
|
-
|
398
|
-
if (pollCount == 0)
|
399
|
-
return 0;
|
400
|
-
|
401
|
-
if (pollSocket.revents & POLLOUT)
|
402
|
-
* condition |= ENET_SOCKET_WAIT_SEND;
|
403
|
-
|
404
|
-
if (pollSocket.revents & POLLIN)
|
405
|
-
* condition |= ENET_SOCKET_WAIT_RECEIVE;
|
406
|
-
|
407
|
-
return 0;
|
408
|
-
#else
|
409
|
-
fd_set readSet, writeSet;
|
410
|
-
struct timeval timeVal;
|
411
|
-
int selectCount;
|
412
|
-
|
413
|
-
timeVal.tv_sec = timeout / 1000;
|
414
|
-
timeVal.tv_usec = (timeout % 1000) * 1000;
|
415
|
-
|
416
|
-
FD_ZERO (& readSet);
|
417
|
-
FD_ZERO (& writeSet);
|
418
|
-
|
419
|
-
if (* condition & ENET_SOCKET_WAIT_SEND)
|
420
|
-
FD_SET (socket, & writeSet);
|
421
|
-
|
422
|
-
if (* condition & ENET_SOCKET_WAIT_RECEIVE)
|
423
|
-
FD_SET (socket, & readSet);
|
424
|
-
|
425
|
-
selectCount = select (socket + 1, & readSet, & writeSet, NULL, & timeVal);
|
426
|
-
|
427
|
-
if (selectCount < 0)
|
428
|
-
return -1;
|
429
|
-
|
430
|
-
* condition = ENET_SOCKET_WAIT_NONE;
|
431
|
-
|
432
|
-
if (selectCount == 0)
|
433
|
-
return 0;
|
434
|
-
|
435
|
-
if (FD_ISSET (socket, & writeSet))
|
436
|
-
* condition |= ENET_SOCKET_WAIT_SEND;
|
437
|
-
|
438
|
-
if (FD_ISSET (socket, & readSet))
|
439
|
-
* condition |= ENET_SOCKET_WAIT_RECEIVE;
|
440
|
-
|
441
|
-
return 0;
|
442
|
-
#endif
|
443
|
-
}
|
444
|
-
|
445
|
-
#endif
|
446
|
-
|
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
|
-
|