renet 0.1.14 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,27 @@
1
+ /**
2
+ @file callbacks.h
3
+ @brief ENet callbacks
4
+ */
5
+ #ifndef __ENET_CALLBACKS_H__
6
+ #define __ENET_CALLBACKS_H__
7
+
8
+ #include <stdlib.h>
9
+
10
+ typedef struct _ENetCallbacks
11
+ {
12
+ void * (ENET_CALLBACK * malloc) (size_t size);
13
+ void (ENET_CALLBACK * free) (void * memory);
14
+ void (ENET_CALLBACK * no_memory) (void);
15
+ } ENetCallbacks;
16
+
17
+ /** @defgroup callbacks ENet internal callbacks
18
+ @{
19
+ @ingroup private
20
+ */
21
+ extern void * enet_malloc (size_t);
22
+ extern void enet_free (void *);
23
+
24
+ /** @} */
25
+
26
+ #endif /* __ENET_CALLBACKS_H__ */
27
+
@@ -0,0 +1,592 @@
1
+ /**
2
+ @file enet.h
3
+ @brief ENet public header file
4
+ */
5
+ #ifndef __ENET_ENET_H__
6
+ #define __ENET_ENET_H__
7
+
8
+ #ifdef __cplusplus
9
+ extern "C"
10
+ {
11
+ #endif
12
+
13
+ #include <stdlib.h>
14
+
15
+ #ifdef _WIN32
16
+ #include "enet/win32.h"
17
+ #else
18
+ #include "enet/unix.h"
19
+ #endif
20
+
21
+ #include "enet/types.h"
22
+ #include "enet/protocol.h"
23
+ #include "enet/list.h"
24
+ #include "enet/callbacks.h"
25
+
26
+ #define ENET_VERSION_MAJOR 1
27
+ #define ENET_VERSION_MINOR 3
28
+ #define ENET_VERSION_PATCH 13
29
+ #define ENET_VERSION_CREATE(major, minor, patch) (((major)<<16) | ((minor)<<8) | (patch))
30
+ #define ENET_VERSION_GET_MAJOR(version) (((version)>>16)&0xFF)
31
+ #define ENET_VERSION_GET_MINOR(version) (((version)>>8)&0xFF)
32
+ #define ENET_VERSION_GET_PATCH(version) ((version)&0xFF)
33
+ #define ENET_VERSION ENET_VERSION_CREATE(ENET_VERSION_MAJOR, ENET_VERSION_MINOR, ENET_VERSION_PATCH)
34
+
35
+ typedef enet_uint32 ENetVersion;
36
+
37
+ struct _ENetHost;
38
+ struct _ENetEvent;
39
+ struct _ENetPacket;
40
+
41
+ typedef enum _ENetSocketType
42
+ {
43
+ ENET_SOCKET_TYPE_STREAM = 1,
44
+ ENET_SOCKET_TYPE_DATAGRAM = 2
45
+ } ENetSocketType;
46
+
47
+ typedef enum _ENetSocketWait
48
+ {
49
+ ENET_SOCKET_WAIT_NONE = 0,
50
+ ENET_SOCKET_WAIT_SEND = (1 << 0),
51
+ ENET_SOCKET_WAIT_RECEIVE = (1 << 1),
52
+ ENET_SOCKET_WAIT_INTERRUPT = (1 << 2)
53
+ } ENetSocketWait;
54
+
55
+ typedef enum _ENetSocketOption
56
+ {
57
+ ENET_SOCKOPT_NONBLOCK = 1,
58
+ ENET_SOCKOPT_BROADCAST = 2,
59
+ ENET_SOCKOPT_RCVBUF = 3,
60
+ ENET_SOCKOPT_SNDBUF = 4,
61
+ ENET_SOCKOPT_REUSEADDR = 5,
62
+ ENET_SOCKOPT_RCVTIMEO = 6,
63
+ ENET_SOCKOPT_SNDTIMEO = 7,
64
+ ENET_SOCKOPT_ERROR = 8,
65
+ ENET_SOCKOPT_NODELAY = 9
66
+ } ENetSocketOption;
67
+
68
+ typedef enum _ENetSocketShutdown
69
+ {
70
+ ENET_SOCKET_SHUTDOWN_READ = 0,
71
+ ENET_SOCKET_SHUTDOWN_WRITE = 1,
72
+ ENET_SOCKET_SHUTDOWN_READ_WRITE = 2
73
+ } ENetSocketShutdown;
74
+
75
+ #define ENET_HOST_ANY 0
76
+ #define ENET_HOST_BROADCAST 0xFFFFFFFFU
77
+ #define ENET_PORT_ANY 0
78
+
79
+ /**
80
+ * Portable internet address structure.
81
+ *
82
+ * The host must be specified in network byte-order, and the port must be in host
83
+ * byte-order. The constant ENET_HOST_ANY may be used to specify the default
84
+ * server host. The constant ENET_HOST_BROADCAST may be used to specify the
85
+ * broadcast address (255.255.255.255). This makes sense for enet_host_connect,
86
+ * but not for enet_host_create. Once a server responds to a broadcast, the
87
+ * address is updated from ENET_HOST_BROADCAST to the server's actual IP address.
88
+ */
89
+ typedef struct _ENetAddress
90
+ {
91
+ enet_uint32 host;
92
+ enet_uint16 port;
93
+ } ENetAddress;
94
+
95
+ /**
96
+ * Packet flag bit constants.
97
+ *
98
+ * The host must be specified in network byte-order, and the port must be in
99
+ * host byte-order. The constant ENET_HOST_ANY may be used to specify the
100
+ * default server host.
101
+
102
+ @sa ENetPacket
103
+ */
104
+ typedef enum _ENetPacketFlag
105
+ {
106
+ /** packet must be received by the target peer and resend attempts should be
107
+ * made until the packet is delivered */
108
+ ENET_PACKET_FLAG_RELIABLE = (1 << 0),
109
+ /** packet will not be sequenced with other packets
110
+ * not supported for reliable packets
111
+ */
112
+ ENET_PACKET_FLAG_UNSEQUENCED = (1 << 1),
113
+ /** packet will not allocate data, and user must supply it instead */
114
+ ENET_PACKET_FLAG_NO_ALLOCATE = (1 << 2),
115
+ /** packet will be fragmented using unreliable (instead of reliable) sends
116
+ * if it exceeds the MTU */
117
+ ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT = (1 << 3),
118
+
119
+ /** whether the packet has been sent from all queues it has been entered into */
120
+ ENET_PACKET_FLAG_SENT = (1<<8)
121
+ } ENetPacketFlag;
122
+
123
+ typedef void (ENET_CALLBACK * ENetPacketFreeCallback) (struct _ENetPacket *);
124
+
125
+ /**
126
+ * ENet packet structure.
127
+ *
128
+ * An ENet data packet that may be sent to or received from a peer. The shown
129
+ * fields should only be read and never modified. The data field contains the
130
+ * allocated data for the packet. The dataLength fields specifies the length
131
+ * of the allocated data. The flags field is either 0 (specifying no flags),
132
+ * or a bitwise-or of any combination of the following flags:
133
+ *
134
+ * ENET_PACKET_FLAG_RELIABLE - packet must be received by the target peer
135
+ * and resend attempts should be made until the packet is delivered
136
+ *
137
+ * ENET_PACKET_FLAG_UNSEQUENCED - packet will not be sequenced with other packets
138
+ * (not supported for reliable packets)
139
+ *
140
+ * ENET_PACKET_FLAG_NO_ALLOCATE - packet will not allocate data, and user must supply it instead
141
+
142
+ @sa ENetPacketFlag
143
+ */
144
+ typedef struct _ENetPacket
145
+ {
146
+ size_t referenceCount; /**< internal use only */
147
+ enet_uint32 flags; /**< bitwise-or of ENetPacketFlag constants */
148
+ enet_uint8 * data; /**< allocated data for packet */
149
+ size_t dataLength; /**< length of data */
150
+ ENetPacketFreeCallback freeCallback; /**< function to be called when the packet is no longer in use */
151
+ void * userData; /**< application private data, may be freely modified */
152
+ } ENetPacket;
153
+
154
+ typedef struct _ENetAcknowledgement
155
+ {
156
+ ENetListNode acknowledgementList;
157
+ enet_uint32 sentTime;
158
+ ENetProtocol command;
159
+ } ENetAcknowledgement;
160
+
161
+ typedef struct _ENetOutgoingCommand
162
+ {
163
+ ENetListNode outgoingCommandList;
164
+ enet_uint16 reliableSequenceNumber;
165
+ enet_uint16 unreliableSequenceNumber;
166
+ enet_uint32 sentTime;
167
+ enet_uint32 roundTripTimeout;
168
+ enet_uint32 roundTripTimeoutLimit;
169
+ enet_uint32 fragmentOffset;
170
+ enet_uint16 fragmentLength;
171
+ enet_uint16 sendAttempts;
172
+ ENetProtocol command;
173
+ ENetPacket * packet;
174
+ } ENetOutgoingCommand;
175
+
176
+ typedef struct _ENetIncomingCommand
177
+ {
178
+ ENetListNode incomingCommandList;
179
+ enet_uint16 reliableSequenceNumber;
180
+ enet_uint16 unreliableSequenceNumber;
181
+ ENetProtocol command;
182
+ enet_uint32 fragmentCount;
183
+ enet_uint32 fragmentsRemaining;
184
+ enet_uint32 * fragments;
185
+ ENetPacket * packet;
186
+ } ENetIncomingCommand;
187
+
188
+ typedef enum _ENetPeerState
189
+ {
190
+ ENET_PEER_STATE_DISCONNECTED = 0,
191
+ ENET_PEER_STATE_CONNECTING = 1,
192
+ ENET_PEER_STATE_ACKNOWLEDGING_CONNECT = 2,
193
+ ENET_PEER_STATE_CONNECTION_PENDING = 3,
194
+ ENET_PEER_STATE_CONNECTION_SUCCEEDED = 4,
195
+ ENET_PEER_STATE_CONNECTED = 5,
196
+ ENET_PEER_STATE_DISCONNECT_LATER = 6,
197
+ ENET_PEER_STATE_DISCONNECTING = 7,
198
+ ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT = 8,
199
+ ENET_PEER_STATE_ZOMBIE = 9
200
+ } ENetPeerState;
201
+
202
+ #ifndef ENET_BUFFER_MAXIMUM
203
+ #define ENET_BUFFER_MAXIMUM (1 + 2 * ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS)
204
+ #endif
205
+
206
+ enum
207
+ {
208
+ ENET_HOST_RECEIVE_BUFFER_SIZE = 256 * 1024,
209
+ ENET_HOST_SEND_BUFFER_SIZE = 256 * 1024,
210
+ ENET_HOST_BANDWIDTH_THROTTLE_INTERVAL = 1000,
211
+ ENET_HOST_DEFAULT_MTU = 1400,
212
+ ENET_HOST_DEFAULT_MAXIMUM_PACKET_SIZE = 32 * 1024 * 1024,
213
+ ENET_HOST_DEFAULT_MAXIMUM_WAITING_DATA = 32 * 1024 * 1024,
214
+
215
+ ENET_PEER_DEFAULT_ROUND_TRIP_TIME = 500,
216
+ ENET_PEER_DEFAULT_PACKET_THROTTLE = 32,
217
+ ENET_PEER_PACKET_THROTTLE_SCALE = 32,
218
+ ENET_PEER_PACKET_THROTTLE_COUNTER = 7,
219
+ ENET_PEER_PACKET_THROTTLE_ACCELERATION = 2,
220
+ ENET_PEER_PACKET_THROTTLE_DECELERATION = 2,
221
+ ENET_PEER_PACKET_THROTTLE_INTERVAL = 5000,
222
+ ENET_PEER_PACKET_LOSS_SCALE = (1 << 16),
223
+ ENET_PEER_PACKET_LOSS_INTERVAL = 10000,
224
+ ENET_PEER_WINDOW_SIZE_SCALE = 64 * 1024,
225
+ ENET_PEER_TIMEOUT_LIMIT = 32,
226
+ ENET_PEER_TIMEOUT_MINIMUM = 5000,
227
+ ENET_PEER_TIMEOUT_MAXIMUM = 30000,
228
+ ENET_PEER_PING_INTERVAL = 500,
229
+ ENET_PEER_UNSEQUENCED_WINDOWS = 64,
230
+ ENET_PEER_UNSEQUENCED_WINDOW_SIZE = 1024,
231
+ ENET_PEER_FREE_UNSEQUENCED_WINDOWS = 32,
232
+ ENET_PEER_RELIABLE_WINDOWS = 16,
233
+ ENET_PEER_RELIABLE_WINDOW_SIZE = 0x1000,
234
+ ENET_PEER_FREE_RELIABLE_WINDOWS = 8
235
+ };
236
+
237
+ typedef struct _ENetChannel
238
+ {
239
+ enet_uint16 outgoingReliableSequenceNumber;
240
+ enet_uint16 outgoingUnreliableSequenceNumber;
241
+ enet_uint16 usedReliableWindows;
242
+ enet_uint16 reliableWindows [ENET_PEER_RELIABLE_WINDOWS];
243
+ enet_uint16 incomingReliableSequenceNumber;
244
+ enet_uint16 incomingUnreliableSequenceNumber;
245
+ ENetList incomingReliableCommands;
246
+ ENetList incomingUnreliableCommands;
247
+ } ENetChannel;
248
+
249
+ /**
250
+ * An ENet peer which data packets may be sent or received from.
251
+ *
252
+ * No fields should be modified unless otherwise specified.
253
+ */
254
+ typedef struct _ENetPeer
255
+ {
256
+ ENetListNode dispatchList;
257
+ struct _ENetHost * host;
258
+ enet_uint16 outgoingPeerID;
259
+ enet_uint16 incomingPeerID;
260
+ enet_uint32 connectID;
261
+ enet_uint8 outgoingSessionID;
262
+ enet_uint8 incomingSessionID;
263
+ ENetAddress address; /**< Internet address of the peer */
264
+ void * data; /**< Application private data, may be freely modified */
265
+ ENetPeerState state;
266
+ ENetChannel * channels;
267
+ size_t channelCount; /**< Number of channels allocated for communication with peer */
268
+ enet_uint32 incomingBandwidth; /**< Downstream bandwidth of the client in bytes/second */
269
+ enet_uint32 outgoingBandwidth; /**< Upstream bandwidth of the client in bytes/second */
270
+ enet_uint32 incomingBandwidthThrottleEpoch;
271
+ enet_uint32 outgoingBandwidthThrottleEpoch;
272
+ enet_uint32 incomingDataTotal;
273
+ enet_uint32 outgoingDataTotal;
274
+ enet_uint32 lastSendTime;
275
+ enet_uint32 lastReceiveTime;
276
+ enet_uint32 nextTimeout;
277
+ enet_uint32 earliestTimeout;
278
+ enet_uint32 packetLossEpoch;
279
+ enet_uint32 packetsSent;
280
+ enet_uint32 packetsLost;
281
+ enet_uint32 packetLoss; /**< mean packet loss of reliable packets as a ratio with respect to the constant ENET_PEER_PACKET_LOSS_SCALE */
282
+ enet_uint32 packetLossVariance;
283
+ enet_uint32 packetThrottle;
284
+ enet_uint32 packetThrottleLimit;
285
+ enet_uint32 packetThrottleCounter;
286
+ enet_uint32 packetThrottleEpoch;
287
+ enet_uint32 packetThrottleAcceleration;
288
+ enet_uint32 packetThrottleDeceleration;
289
+ enet_uint32 packetThrottleInterval;
290
+ enet_uint32 pingInterval;
291
+ enet_uint32 timeoutLimit;
292
+ enet_uint32 timeoutMinimum;
293
+ enet_uint32 timeoutMaximum;
294
+ enet_uint32 lastRoundTripTime;
295
+ enet_uint32 lowestRoundTripTime;
296
+ enet_uint32 lastRoundTripTimeVariance;
297
+ enet_uint32 highestRoundTripTimeVariance;
298
+ enet_uint32 roundTripTime; /**< mean round trip time (RTT), in milliseconds, between sending a reliable packet and receiving its acknowledgement */
299
+ enet_uint32 roundTripTimeVariance;
300
+ enet_uint32 mtu;
301
+ enet_uint32 windowSize;
302
+ enet_uint32 reliableDataInTransit;
303
+ enet_uint16 outgoingReliableSequenceNumber;
304
+ ENetList acknowledgements;
305
+ ENetList sentReliableCommands;
306
+ ENetList sentUnreliableCommands;
307
+ ENetList outgoingReliableCommands;
308
+ ENetList outgoingUnreliableCommands;
309
+ ENetList dispatchedCommands;
310
+ int needsDispatch;
311
+ enet_uint16 incomingUnsequencedGroup;
312
+ enet_uint16 outgoingUnsequencedGroup;
313
+ enet_uint32 unsequencedWindow [ENET_PEER_UNSEQUENCED_WINDOW_SIZE / 32];
314
+ enet_uint32 eventData;
315
+ size_t totalWaitingData;
316
+ } ENetPeer;
317
+
318
+ /** An ENet packet compressor for compressing UDP packets before socket sends or receives.
319
+ */
320
+ typedef struct _ENetCompressor
321
+ {
322
+ /** Context data for the compressor. Must be non-NULL. */
323
+ void * context;
324
+ /** Compresses from inBuffers[0:inBufferCount-1], containing inLimit bytes, to outData, outputting at most outLimit bytes. Should return 0 on failure. */
325
+ size_t (ENET_CALLBACK * compress) (void * context, const ENetBuffer * inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 * outData, size_t outLimit);
326
+ /** Decompresses from inData, containing inLimit bytes, to outData, outputting at most outLimit bytes. Should return 0 on failure. */
327
+ size_t (ENET_CALLBACK * decompress) (void * context, const enet_uint8 * inData, size_t inLimit, enet_uint8 * outData, size_t outLimit);
328
+ /** Destroys the context when compression is disabled or the host is destroyed. May be NULL. */
329
+ void (ENET_CALLBACK * destroy) (void * context);
330
+ } ENetCompressor;
331
+
332
+ /** Callback that computes the checksum of the data held in buffers[0:bufferCount-1] */
333
+ typedef enet_uint32 (ENET_CALLBACK * ENetChecksumCallback) (const ENetBuffer * buffers, size_t bufferCount);
334
+
335
+ /** Callback for intercepting received raw UDP packets. Should return 1 to intercept, 0 to ignore, or -1 to propagate an error. */
336
+ typedef int (ENET_CALLBACK * ENetInterceptCallback) (struct _ENetHost * host, struct _ENetEvent * event);
337
+
338
+ /** An ENet host for communicating with peers.
339
+ *
340
+ * No fields should be modified unless otherwise stated.
341
+
342
+ @sa enet_host_create()
343
+ @sa enet_host_destroy()
344
+ @sa enet_host_connect()
345
+ @sa enet_host_service()
346
+ @sa enet_host_flush()
347
+ @sa enet_host_broadcast()
348
+ @sa enet_host_compress()
349
+ @sa enet_host_compress_with_range_coder()
350
+ @sa enet_host_channel_limit()
351
+ @sa enet_host_bandwidth_limit()
352
+ @sa enet_host_bandwidth_throttle()
353
+ */
354
+ typedef struct _ENetHost
355
+ {
356
+ ENetSocket socket;
357
+ ENetAddress address; /**< Internet address of the host */
358
+ enet_uint32 incomingBandwidth; /**< downstream bandwidth of the host */
359
+ enet_uint32 outgoingBandwidth; /**< upstream bandwidth of the host */
360
+ enet_uint32 bandwidthThrottleEpoch;
361
+ enet_uint32 mtu;
362
+ enet_uint32 randomSeed;
363
+ int recalculateBandwidthLimits;
364
+ ENetPeer * peers; /**< array of peers allocated for this host */
365
+ size_t peerCount; /**< number of peers allocated for this host */
366
+ size_t channelLimit; /**< maximum number of channels allowed for connected peers */
367
+ enet_uint32 serviceTime;
368
+ ENetList dispatchQueue;
369
+ int continueSending;
370
+ size_t packetSize;
371
+ enet_uint16 headerFlags;
372
+ ENetProtocol commands [ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS];
373
+ size_t commandCount;
374
+ ENetBuffer buffers [ENET_BUFFER_MAXIMUM];
375
+ size_t bufferCount;
376
+ ENetChecksumCallback checksum; /**< callback the user can set to enable packet checksums for this host */
377
+ ENetCompressor compressor;
378
+ enet_uint8 packetData [2][ENET_PROTOCOL_MAXIMUM_MTU];
379
+ ENetAddress receivedAddress;
380
+ enet_uint8 * receivedData;
381
+ size_t receivedDataLength;
382
+ enet_uint32 totalSentData; /**< total data sent, user should reset to 0 as needed to prevent overflow */
383
+ enet_uint32 totalSentPackets; /**< total UDP packets sent, user should reset to 0 as needed to prevent overflow */
384
+ enet_uint32 totalReceivedData; /**< total data received, user should reset to 0 as needed to prevent overflow */
385
+ enet_uint32 totalReceivedPackets; /**< total UDP packets received, user should reset to 0 as needed to prevent overflow */
386
+ ENetInterceptCallback intercept; /**< callback the user can set to intercept received raw UDP packets */
387
+ size_t connectedPeers;
388
+ size_t bandwidthLimitedPeers;
389
+ size_t duplicatePeers; /**< optional number of allowed peers from duplicate IPs, defaults to ENET_PROTOCOL_MAXIMUM_PEER_ID */
390
+ size_t maximumPacketSize; /**< the maximum allowable packet size that may be sent or received on a peer */
391
+ size_t maximumWaitingData; /**< the maximum aggregate amount of buffer space a peer may use waiting for packets to be delivered */
392
+ } ENetHost;
393
+
394
+ /**
395
+ * An ENet event type, as specified in @ref ENetEvent.
396
+ */
397
+ typedef enum _ENetEventType
398
+ {
399
+ /** no event occurred within the specified time limit */
400
+ ENET_EVENT_TYPE_NONE = 0,
401
+
402
+ /** a connection request initiated by enet_host_connect has completed.
403
+ * The peer field contains the peer which successfully connected.
404
+ */
405
+ ENET_EVENT_TYPE_CONNECT = 1,
406
+
407
+ /** a peer has disconnected. This event is generated on a successful
408
+ * completion of a disconnect initiated by enet_pper_disconnect, if
409
+ * a peer has timed out, or if a connection request intialized by
410
+ * enet_host_connect has timed out. The peer field contains the peer
411
+ * which disconnected. The data field contains user supplied data
412
+ * describing the disconnection, or 0, if none is available.
413
+ */
414
+ ENET_EVENT_TYPE_DISCONNECT = 2,
415
+
416
+ /** a packet has been received from a peer. The peer field specifies the
417
+ * peer which sent the packet. The channelID field specifies the channel
418
+ * number upon which the packet was received. The packet field contains
419
+ * the packet that was received; this packet must be destroyed with
420
+ * enet_packet_destroy after use.
421
+ */
422
+ ENET_EVENT_TYPE_RECEIVE = 3
423
+ } ENetEventType;
424
+
425
+ /**
426
+ * An ENet event as returned by enet_host_service().
427
+
428
+ @sa enet_host_service
429
+ */
430
+ typedef struct _ENetEvent
431
+ {
432
+ ENetEventType type; /**< type of the event */
433
+ ENetPeer * peer; /**< peer that generated a connect, disconnect or receive event */
434
+ enet_uint8 channelID; /**< channel on the peer that generated the event, if appropriate */
435
+ enet_uint32 data; /**< data associated with the event, if appropriate */
436
+ ENetPacket * packet; /**< packet associated with the event, if appropriate */
437
+ } ENetEvent;
438
+
439
+ /** @defgroup global ENet global functions
440
+ @{
441
+ */
442
+
443
+ /**
444
+ Initializes ENet globally. Must be called prior to using any functions in
445
+ ENet.
446
+ @returns 0 on success, < 0 on failure
447
+ */
448
+ ENET_API int enet_initialize (void);
449
+
450
+ /**
451
+ Initializes ENet globally and supplies user-overridden callbacks. Must be called prior to using any functions in ENet. Do not use enet_initialize() if you use this variant. Make sure the ENetCallbacks structure is zeroed out so that any additional callbacks added in future versions will be properly ignored.
452
+
453
+ @param version the constant ENET_VERSION should be supplied so ENet knows which version of ENetCallbacks struct to use
454
+ @param inits user-overridden callbacks where any NULL callbacks will use ENet's defaults
455
+ @returns 0 on success, < 0 on failure
456
+ */
457
+ ENET_API int enet_initialize_with_callbacks (ENetVersion version, const ENetCallbacks * inits);
458
+
459
+ /**
460
+ Shuts down ENet globally. Should be called when a program that has
461
+ initialized ENet exits.
462
+ */
463
+ ENET_API void enet_deinitialize (void);
464
+
465
+ /**
466
+ Gives the linked version of the ENet library.
467
+ @returns the version number
468
+ */
469
+ ENET_API ENetVersion enet_linked_version (void);
470
+
471
+ /** @} */
472
+
473
+ /** @defgroup private ENet private implementation functions */
474
+
475
+ /**
476
+ Returns the wall-time in milliseconds. Its initial value is unspecified
477
+ unless otherwise set.
478
+ */
479
+ ENET_API enet_uint32 enet_time_get (void);
480
+ /**
481
+ Sets the current wall-time in milliseconds.
482
+ */
483
+ ENET_API void enet_time_set (enet_uint32);
484
+
485
+ /** @defgroup socket ENet socket functions
486
+ @{
487
+ */
488
+ ENET_API ENetSocket enet_socket_create (ENetSocketType);
489
+ ENET_API int enet_socket_bind (ENetSocket, const ENetAddress *);
490
+ ENET_API int enet_socket_get_address (ENetSocket, ENetAddress *);
491
+ ENET_API int enet_socket_listen (ENetSocket, int);
492
+ ENET_API ENetSocket enet_socket_accept (ENetSocket, ENetAddress *);
493
+ ENET_API int enet_socket_connect (ENetSocket, const ENetAddress *);
494
+ ENET_API int enet_socket_send (ENetSocket, const ENetAddress *, const ENetBuffer *, size_t);
495
+ ENET_API int enet_socket_receive (ENetSocket, ENetAddress *, ENetBuffer *, size_t);
496
+ ENET_API int enet_socket_wait (ENetSocket, enet_uint32 *, enet_uint32);
497
+ ENET_API int enet_socket_set_option (ENetSocket, ENetSocketOption, int);
498
+ ENET_API int enet_socket_get_option (ENetSocket, ENetSocketOption, int *);
499
+ ENET_API int enet_socket_shutdown (ENetSocket, ENetSocketShutdown);
500
+ ENET_API void enet_socket_destroy (ENetSocket);
501
+ ENET_API int enet_socketset_select (ENetSocket, ENetSocketSet *, ENetSocketSet *, enet_uint32);
502
+
503
+ /** @} */
504
+
505
+ /** @defgroup Address ENet address functions
506
+ @{
507
+ */
508
+ /** Attempts to resolve the host named by the parameter hostName and sets
509
+ the host field in the address parameter if successful.
510
+ @param address destination to store resolved address
511
+ @param hostName host name to lookup
512
+ @retval 0 on success
513
+ @retval < 0 on failure
514
+ @returns the address of the given hostName in address on success
515
+ */
516
+ ENET_API int enet_address_set_host (ENetAddress * address, const char * hostName);
517
+
518
+ /** Gives the printable form of the IP address specified in the address parameter.
519
+ @param address address printed
520
+ @param hostName destination for name, must not be NULL
521
+ @param nameLength maximum length of hostName.
522
+ @returns the null-terminated name of the host in hostName on success
523
+ @retval 0 on success
524
+ @retval < 0 on failure
525
+ */
526
+ ENET_API int enet_address_get_host_ip (const ENetAddress * address, char * hostName, size_t nameLength);
527
+
528
+ /** Attempts to do a reverse lookup of the host field in the address parameter.
529
+ @param address address used for reverse lookup
530
+ @param hostName destination for name, must not be NULL
531
+ @param nameLength maximum length of hostName.
532
+ @returns the null-terminated name of the host in hostName on success
533
+ @retval 0 on success
534
+ @retval < 0 on failure
535
+ */
536
+ ENET_API int enet_address_get_host (const ENetAddress * address, char * hostName, size_t nameLength);
537
+
538
+ /** @} */
539
+
540
+ ENET_API ENetPacket * enet_packet_create (const void *, size_t, enet_uint32);
541
+ ENET_API void enet_packet_destroy (ENetPacket *);
542
+ ENET_API int enet_packet_resize (ENetPacket *, size_t);
543
+ ENET_API enet_uint32 enet_crc32 (const ENetBuffer *, size_t);
544
+
545
+ ENET_API ENetHost * enet_host_create (const ENetAddress *, size_t, size_t, enet_uint32, enet_uint32);
546
+ ENET_API void enet_host_destroy (ENetHost *);
547
+ ENET_API ENetPeer * enet_host_connect (ENetHost *, const ENetAddress *, size_t, enet_uint32);
548
+ ENET_API int enet_host_check_events (ENetHost *, ENetEvent *);
549
+ ENET_API int enet_host_service (ENetHost *, ENetEvent *, enet_uint32);
550
+ ENET_API void enet_host_flush (ENetHost *);
551
+ ENET_API void enet_host_broadcast (ENetHost *, enet_uint8, ENetPacket *);
552
+ ENET_API void enet_host_compress (ENetHost *, const ENetCompressor *);
553
+ ENET_API int enet_host_compress_with_range_coder (ENetHost * host);
554
+ ENET_API void enet_host_channel_limit (ENetHost *, size_t);
555
+ ENET_API void enet_host_bandwidth_limit (ENetHost *, enet_uint32, enet_uint32);
556
+ extern void enet_host_bandwidth_throttle (ENetHost *);
557
+ extern enet_uint32 enet_host_random_seed (void);
558
+
559
+ ENET_API int enet_peer_send (ENetPeer *, enet_uint8, ENetPacket *);
560
+ ENET_API ENetPacket * enet_peer_receive (ENetPeer *, enet_uint8 * channelID);
561
+ ENET_API void enet_peer_ping (ENetPeer *);
562
+ ENET_API void enet_peer_ping_interval (ENetPeer *, enet_uint32);
563
+ ENET_API void enet_peer_timeout (ENetPeer *, enet_uint32, enet_uint32, enet_uint32);
564
+ ENET_API void enet_peer_reset (ENetPeer *);
565
+ ENET_API void enet_peer_disconnect (ENetPeer *, enet_uint32);
566
+ ENET_API void enet_peer_disconnect_now (ENetPeer *, enet_uint32);
567
+ ENET_API void enet_peer_disconnect_later (ENetPeer *, enet_uint32);
568
+ ENET_API void enet_peer_throttle_configure (ENetPeer *, enet_uint32, enet_uint32, enet_uint32);
569
+ extern int enet_peer_throttle (ENetPeer *, enet_uint32);
570
+ extern void enet_peer_reset_queues (ENetPeer *);
571
+ extern void enet_peer_setup_outgoing_command (ENetPeer *, ENetOutgoingCommand *);
572
+ extern ENetOutgoingCommand * enet_peer_queue_outgoing_command (ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32, enet_uint16);
573
+ extern ENetIncomingCommand * enet_peer_queue_incoming_command (ENetPeer *, const ENetProtocol *, const void *, size_t, enet_uint32, enet_uint32);
574
+ extern ENetAcknowledgement * enet_peer_queue_acknowledgement (ENetPeer *, const ENetProtocol *, enet_uint16);
575
+ extern void enet_peer_dispatch_incoming_unreliable_commands (ENetPeer *, ENetChannel *);
576
+ extern void enet_peer_dispatch_incoming_reliable_commands (ENetPeer *, ENetChannel *);
577
+ extern void enet_peer_on_connect (ENetPeer *);
578
+ extern void enet_peer_on_disconnect (ENetPeer *);
579
+
580
+ ENET_API void * enet_range_coder_create (void);
581
+ ENET_API void enet_range_coder_destroy (void *);
582
+ ENET_API size_t enet_range_coder_compress (void *, const ENetBuffer *, size_t, size_t, enet_uint8 *, size_t);
583
+ ENET_API size_t enet_range_coder_decompress (void *, const enet_uint8 *, size_t, enet_uint8 *, size_t);
584
+
585
+ extern size_t enet_protocol_command_size (enet_uint8);
586
+
587
+ #ifdef __cplusplus
588
+ }
589
+ #endif
590
+
591
+ #endif /* __ENET_ENET_H__ */
592
+