ScummVM API documentation
enet.h
1 
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 "win32.h"
17 #else
18 #include "unix.h"
19 #endif
20 
21 #include "types.h"
22 #include "protocol.h"
23 #include "list.h"
24 #include "callbacks.h"
25 
26 #define ENET_VERSION_MAJOR 1
27 #define ENET_VERSION_MINOR 3
28 #define ENET_VERSION_PATCH 17
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 
89 typedef struct _ENetAddress
90 {
91  enet_uint32 host;
92  enet_uint16 port;
93 } ENetAddress;
94 
104 typedef enum _ENetPacketFlag
105 {
108  ENET_PACKET_FLAG_RELIABLE = (1 << 0),
112  ENET_PACKET_FLAG_UNSEQUENCED = (1 << 1),
114  ENET_PACKET_FLAG_NO_ALLOCATE = (1 << 2),
117  ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT = (1 << 3),
118 
120  ENET_PACKET_FLAG_SENT = (1<<8)
121 } ENetPacketFlag;
122 
123 typedef void (ENET_CALLBACK * ENetPacketFreeCallback) (struct _ENetPacket *);
124 
148 typedef struct _ENetPacket
149 {
150  size_t referenceCount;
151  enet_uint32 flags;
152  enet_uint8 * data;
153  size_t dataLength;
154  ENetPacketFreeCallback freeCallback;
155  void * userData;
156 } ENetPacket;
157 
158 typedef struct _ENetAcknowledgement
159 {
160  ENetListNode acknowledgementList;
161  enet_uint32 sentTime;
162  ENetProtocol command;
164 
165 typedef struct _ENetOutgoingCommand
166 {
167  ENetListNode outgoingCommandList;
168  enet_uint16 reliableSequenceNumber;
169  enet_uint16 unreliableSequenceNumber;
170  enet_uint32 sentTime;
171  enet_uint32 roundTripTimeout;
172  enet_uint32 roundTripTimeoutLimit;
173  enet_uint32 fragmentOffset;
174  enet_uint16 fragmentLength;
175  enet_uint16 sendAttempts;
176  ENetProtocol command;
177  ENetPacket * packet;
179 
180 typedef struct _ENetIncomingCommand
181 {
182  ENetListNode incomingCommandList;
183  enet_uint16 reliableSequenceNumber;
184  enet_uint16 unreliableSequenceNumber;
185  ENetProtocol command;
186  enet_uint32 fragmentCount;
187  enet_uint32 fragmentsRemaining;
188  enet_uint32 * fragments;
189  ENetPacket * packet;
191 
192 typedef enum _ENetPeerState
193 {
194  ENET_PEER_STATE_DISCONNECTED = 0,
195  ENET_PEER_STATE_CONNECTING = 1,
196  ENET_PEER_STATE_ACKNOWLEDGING_CONNECT = 2,
197  ENET_PEER_STATE_CONNECTION_PENDING = 3,
198  ENET_PEER_STATE_CONNECTION_SUCCEEDED = 4,
199  ENET_PEER_STATE_CONNECTED = 5,
200  ENET_PEER_STATE_DISCONNECT_LATER = 6,
201  ENET_PEER_STATE_DISCONNECTING = 7,
202  ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT = 8,
203  ENET_PEER_STATE_ZOMBIE = 9
204 } ENetPeerState;
205 
206 #ifndef ENET_BUFFER_MAXIMUM
207 #define ENET_BUFFER_MAXIMUM (1 + 2 * ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS)
208 #endif
209 
210 enum
211 {
212  ENET_HOST_RECEIVE_BUFFER_SIZE = 256 * 1024,
213  ENET_HOST_SEND_BUFFER_SIZE = 256 * 1024,
214  ENET_HOST_BANDWIDTH_THROTTLE_INTERVAL = 1000,
215  ENET_HOST_DEFAULT_MTU = 1400,
216  ENET_HOST_DEFAULT_MAXIMUM_PACKET_SIZE = 32 * 1024 * 1024,
217  ENET_HOST_DEFAULT_MAXIMUM_WAITING_DATA = 32 * 1024 * 1024,
218 
219  ENET_PEER_DEFAULT_ROUND_TRIP_TIME = 500,
220  ENET_PEER_DEFAULT_PACKET_THROTTLE = 32,
221  ENET_PEER_PACKET_THROTTLE_SCALE = 32,
222  ENET_PEER_PACKET_THROTTLE_COUNTER = 7,
223  ENET_PEER_PACKET_THROTTLE_ACCELERATION = 2,
224  ENET_PEER_PACKET_THROTTLE_DECELERATION = 2,
225  ENET_PEER_PACKET_THROTTLE_INTERVAL = 5000,
226  ENET_PEER_PACKET_LOSS_SCALE = (1 << 16),
227  ENET_PEER_PACKET_LOSS_INTERVAL = 10000,
228  ENET_PEER_WINDOW_SIZE_SCALE = 64 * 1024,
229  ENET_PEER_TIMEOUT_LIMIT = 32,
230  ENET_PEER_TIMEOUT_MINIMUM = 5000,
231  ENET_PEER_TIMEOUT_MAXIMUM = 30000,
232  ENET_PEER_PING_INTERVAL = 500,
233  ENET_PEER_UNSEQUENCED_WINDOWS = 64,
234  ENET_PEER_UNSEQUENCED_WINDOW_SIZE = 1024,
235  ENET_PEER_FREE_UNSEQUENCED_WINDOWS = 32,
236  ENET_PEER_RELIABLE_WINDOWS = 16,
237  ENET_PEER_RELIABLE_WINDOW_SIZE = 0x1000,
238  ENET_PEER_FREE_RELIABLE_WINDOWS = 8
239 };
240 
241 typedef struct _ENetChannel
242 {
243  enet_uint16 outgoingReliableSequenceNumber;
244  enet_uint16 outgoingUnreliableSequenceNumber;
245  enet_uint16 usedReliableWindows;
246  enet_uint16 reliableWindows [ENET_PEER_RELIABLE_WINDOWS];
247  enet_uint16 incomingReliableSequenceNumber;
248  enet_uint16 incomingUnreliableSequenceNumber;
249  ENetList incomingReliableCommands;
250  ENetList incomingUnreliableCommands;
251 } ENetChannel;
252 
253 typedef enum _ENetPeerFlag
254 {
255  ENET_PEER_FLAG_NEEDS_DISPATCH = (1 << 0)
256 } ENetPeerFlag;
257 
263 typedef struct _ENetPeer
264 {
265  ENetListNode dispatchList;
266  struct _ENetHost * host;
267  enet_uint16 outgoingPeerID;
268  enet_uint16 incomingPeerID;
269  enet_uint32 connectID;
270  enet_uint8 outgoingSessionID;
271  enet_uint8 incomingSessionID;
273  void * data;
274  ENetPeerState state;
275  ENetChannel * channels;
276  size_t channelCount;
277  enet_uint32 incomingBandwidth;
278  enet_uint32 outgoingBandwidth;
279  enet_uint32 incomingBandwidthThrottleEpoch;
280  enet_uint32 outgoingBandwidthThrottleEpoch;
281  enet_uint32 incomingDataTotal;
282  enet_uint32 outgoingDataTotal;
283  enet_uint32 lastSendTime;
284  enet_uint32 lastReceiveTime;
285  enet_uint32 nextTimeout;
286  enet_uint32 earliestTimeout;
287  enet_uint32 packetLossEpoch;
288  enet_uint32 packetsSent;
289  enet_uint32 packetsLost;
290  enet_uint32 packetLoss;
291  enet_uint32 packetLossVariance;
292  enet_uint32 packetThrottle;
293  enet_uint32 packetThrottleLimit;
294  enet_uint32 packetThrottleCounter;
295  enet_uint32 packetThrottleEpoch;
296  enet_uint32 packetThrottleAcceleration;
297  enet_uint32 packetThrottleDeceleration;
298  enet_uint32 packetThrottleInterval;
299  enet_uint32 pingInterval;
300  enet_uint32 timeoutLimit;
301  enet_uint32 timeoutMinimum;
302  enet_uint32 timeoutMaximum;
303  enet_uint32 lastRoundTripTime;
304  enet_uint32 lowestRoundTripTime;
305  enet_uint32 lastRoundTripTimeVariance;
306  enet_uint32 highestRoundTripTimeVariance;
307  enet_uint32 roundTripTime;
308  enet_uint32 roundTripTimeVariance;
309  enet_uint32 mtu;
310  enet_uint32 windowSize;
311  enet_uint32 reliableDataInTransit;
312  enet_uint16 outgoingReliableSequenceNumber;
313  ENetList acknowledgements;
314  ENetList sentReliableCommands;
315  ENetList sentUnreliableCommands;
316  ENetList outgoingCommands;
317  ENetList dispatchedCommands;
318  enet_uint16 flags;
319  enet_uint16 reserved;
320  enet_uint16 incomingUnsequencedGroup;
321  enet_uint16 outgoingUnsequencedGroup;
322  enet_uint32 unsequencedWindow [ENET_PEER_UNSEQUENCED_WINDOW_SIZE / 32];
323  enet_uint32 eventData;
324  size_t totalWaitingData;
325 } ENetPeer;
326 
329 typedef struct _ENetCompressor
330 {
332  void * context;
334  size_t (ENET_CALLBACK * compress) (void * context, const ENetBuffer * inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 * outData, size_t outLimit);
336  size_t (ENET_CALLBACK * decompress) (void * context, const enet_uint8 * inData, size_t inLimit, enet_uint8 * outData, size_t outLimit);
338  void (ENET_CALLBACK * destroy) (void * context);
340 
342 typedef enet_uint32 (ENET_CALLBACK * ENetChecksumCallback) (const ENetBuffer * buffers, size_t bufferCount);
343 
345 typedef int (ENET_CALLBACK * ENetInterceptCallback) (struct _ENetHost * host, struct _ENetEvent * event);
346 
363 typedef struct _ENetHost
364 {
365  ENetSocket socket;
367  enet_uint32 incomingBandwidth;
368  enet_uint32 outgoingBandwidth;
369  enet_uint32 bandwidthThrottleEpoch;
370  enet_uint32 mtu;
371  enet_uint32 randomSeed;
372  int recalculateBandwidthLimits;
374  size_t peerCount;
375  size_t channelLimit;
376  enet_uint32 serviceTime;
377  ENetList dispatchQueue;
378  int continueSending;
379  size_t packetSize;
380  enet_uint16 headerFlags;
381  ENetProtocol commands [ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS];
382  size_t commandCount;
383  ENetBuffer buffers [ENET_BUFFER_MAXIMUM];
384  size_t bufferCount;
385  ENetChecksumCallback checksum;
386  ENetCompressor compressor;
387  enet_uint8 packetData [2][ENET_PROTOCOL_MAXIMUM_MTU];
388  ENetAddress receivedAddress;
389  enet_uint8 * receivedData;
390  size_t receivedDataLength;
391  enet_uint32 totalSentData;
392  enet_uint32 totalSentPackets;
393  enet_uint32 totalReceivedData;
394  enet_uint32 totalReceivedPackets;
395  ENetInterceptCallback intercept;
396  size_t connectedPeers;
397  size_t bandwidthLimitedPeers;
398  size_t duplicatePeers;
401 } ENetHost;
402 
406 typedef enum _ENetEventType
407 {
409  ENET_EVENT_TYPE_NONE = 0,
410 
414  ENET_EVENT_TYPE_CONNECT = 1,
415 
423  ENET_EVENT_TYPE_DISCONNECT = 2,
424 
431  ENET_EVENT_TYPE_RECEIVE = 3
432 } ENetEventType;
433 
439 typedef struct _ENetEvent
440 {
441  ENetEventType type;
443  enet_uint8 channelID;
444  enet_uint32 data;
446 } ENetEvent;
447 
457 ENET_API int enet_initialize (void);
458 
466 ENET_API int enet_initialize_with_callbacks (ENetVersion version, const ENetCallbacks * inits);
467 
472 ENET_API void enet_deinitialize (void);
473 
478 ENET_API ENetVersion enet_linked_version (void);
479 
488 ENET_API enet_uint32 enet_time_get (void);
492 ENET_API void enet_time_set (enet_uint32);
493 
497 ENET_API ENetSocket enet_socket_create (ENetSocketType);
498 ENET_API int enet_socket_bind (ENetSocket, const ENetAddress *);
499 ENET_API int enet_socket_get_address (ENetSocket, ENetAddress *);
500 ENET_API int enet_socket_listen (ENetSocket, int);
501 ENET_API ENetSocket enet_socket_accept (ENetSocket, ENetAddress *);
502 ENET_API int enet_socket_connect (ENetSocket, const ENetAddress *);
503 ENET_API int enet_socket_send (ENetSocket, const ENetAddress *, const ENetBuffer *, size_t);
504 ENET_API int enet_socket_receive (ENetSocket, ENetAddress *, ENetBuffer *, size_t);
505 ENET_API int enet_socket_wait (ENetSocket, enet_uint32 *, enet_uint32);
506 ENET_API int enet_socket_set_option (ENetSocket, ENetSocketOption, int);
507 ENET_API int enet_socket_get_option (ENetSocket, ENetSocketOption, int *);
508 ENET_API int enet_socket_shutdown (ENetSocket, ENetSocketShutdown);
509 ENET_API void enet_socket_destroy (ENetSocket);
510 ENET_API int enet_socketset_select (ENetSocket, ENetSocketSet *, ENetSocketSet *, enet_uint32);
511 
526 ENET_API int enet_address_set_host_ip (ENetAddress * address, const char * hostName);
527 
536 ENET_API int enet_address_set_host (ENetAddress * address, const char * hostName);
537 
546 ENET_API int enet_address_get_host_ip (const ENetAddress * address, char * hostName, size_t nameLength);
547 
556 ENET_API int enet_address_get_host (const ENetAddress * address, char * hostName, size_t nameLength);
557 
560 ENET_API ENetPacket * enet_packet_create (const void *, size_t, enet_uint32);
561 ENET_API void enet_packet_destroy (ENetPacket *);
562 ENET_API int enet_packet_resize (ENetPacket *, size_t);
563 ENET_API enet_uint32 enet_crc32 (const ENetBuffer *, size_t);
564 
565 ENET_API ENetHost * enet_host_create (const ENetAddress *, size_t, size_t, enet_uint32, enet_uint32);
566 ENET_API void enet_host_destroy (ENetHost *);
567 ENET_API ENetPeer * enet_host_connect (ENetHost *, const ENetAddress *, size_t, enet_uint32);
568 ENET_API int enet_host_check_events (ENetHost *, ENetEvent *);
569 ENET_API int enet_host_service (ENetHost *, ENetEvent *, enet_uint32);
570 ENET_API void enet_host_flush (ENetHost *);
571 ENET_API void enet_host_broadcast (ENetHost *, enet_uint8, ENetPacket *);
572 ENET_API void enet_host_compress (ENetHost *, const ENetCompressor *);
573 ENET_API int enet_host_compress_with_range_coder (ENetHost * host);
574 ENET_API void enet_host_channel_limit (ENetHost *, size_t);
575 ENET_API void enet_host_bandwidth_limit (ENetHost *, enet_uint32, enet_uint32);
576 extern void enet_host_bandwidth_throttle (ENetHost *);
577 extern enet_uint32 enet_host_random_seed (void);
578 
579 ENET_API int enet_peer_send (ENetPeer *, enet_uint8, ENetPacket *);
580 ENET_API ENetPacket * enet_peer_receive (ENetPeer *, enet_uint8 * channelID);
581 ENET_API void enet_peer_ping (ENetPeer *);
582 ENET_API void enet_peer_ping_interval (ENetPeer *, enet_uint32);
583 ENET_API void enet_peer_timeout (ENetPeer *, enet_uint32, enet_uint32, enet_uint32);
584 ENET_API void enet_peer_reset (ENetPeer *);
585 ENET_API void enet_peer_disconnect (ENetPeer *, enet_uint32);
586 ENET_API void enet_peer_disconnect_now (ENetPeer *, enet_uint32);
587 ENET_API void enet_peer_disconnect_later (ENetPeer *, enet_uint32);
588 ENET_API void enet_peer_throttle_configure (ENetPeer *, enet_uint32, enet_uint32, enet_uint32);
589 extern int enet_peer_throttle (ENetPeer *, enet_uint32);
590 extern void enet_peer_reset_queues (ENetPeer *);
591 extern void enet_peer_setup_outgoing_command (ENetPeer *, ENetOutgoingCommand *);
592 extern ENetOutgoingCommand * enet_peer_queue_outgoing_command (ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32, enet_uint16);
593 extern ENetIncomingCommand * enet_peer_queue_incoming_command (ENetPeer *, const ENetProtocol *, const void *, size_t, enet_uint32, enet_uint32);
594 extern ENetAcknowledgement * enet_peer_queue_acknowledgement (ENetPeer *, const ENetProtocol *, enet_uint16);
595 extern void enet_peer_dispatch_incoming_unreliable_commands (ENetPeer *, ENetChannel *, ENetIncomingCommand *);
596 extern void enet_peer_dispatch_incoming_reliable_commands (ENetPeer *, ENetChannel *, ENetIncomingCommand *);
597 extern void enet_peer_on_connect (ENetPeer *);
598 extern void enet_peer_on_disconnect (ENetPeer *);
599 
600 ENET_API void * enet_range_coder_create (void);
601 ENET_API void enet_range_coder_destroy (void *);
602 ENET_API size_t enet_range_coder_compress (void *, const ENetBuffer *, size_t, size_t, enet_uint8 *, size_t);
603 ENET_API size_t enet_range_coder_decompress (void *, const enet_uint8 *, size_t, enet_uint8 *, size_t);
604 
605 extern size_t enet_protocol_command_size (enet_uint8);
606 
607 #ifdef __cplusplus
608 }
609 #endif
610 
611 #endif /* __ENET_ENET_H__ */
612 
Definition: enet.h:89
size_t maximumWaitingData
Definition: enet.h:400
Definition: list.h:10
Definition: callbacks.h:10
ENetPeer * peers
Definition: enet.h:373
int enet_address_set_host_ip(ENetAddress *address, const char *hostName)
Definition: enet.h:241
size_t peerCount
Definition: enet.h:374
enet_uint32 totalSentData
Definition: enet.h:391
enet_uint32 outgoingBandwidth
Definition: enet.h:368
size_t referenceCount
Definition: enet.h:150
enet_uint32 totalReceivedPackets
Definition: enet.h:394
enet_uint32 packetLoss
Definition: enet.h:290
enet_uint32 totalSentPackets
Definition: enet.h:392
Definition: enet.h:363
ENetAddress address
Definition: enet.h:272
ENetPeer * peer
Definition: enet.h:442
enet_uint8 channelID
Definition: enet.h:443
int enet_address_get_host_ip(const ENetAddress *address, char *hostName, size_t nameLength)
ENetPacket * packet
Definition: enet.h:445
void * context
Definition: enet.h:332
Definition: enet.h:158
Definition: enet.h:439
enet_uint32 outgoingBandwidth
Definition: enet.h:278
Definition: enet.h:263
enet_uint32 flags
Definition: enet.h:151
int enet_address_get_host(const ENetAddress *address, char *hostName, size_t nameLength)
size_t duplicatePeers
Definition: enet.h:398
size_t dataLength
Definition: enet.h:153
size_t maximumPacketSize
Definition: enet.h:399
ENetInterceptCallback intercept
Definition: enet.h:395
int enet_initialize(void)
Definition: enet.h:165
int enet_address_set_host(ENetAddress *address, const char *hostName)
enet_uint32 totalReceivedData
Definition: enet.h:393
ENetEventType type
Definition: enet.h:441
void * data
Definition: enet.h:273
enet_uint32 roundTripTime
Definition: enet.h:307
Definition: unix.h:30
Definition: protocol.h:177
enet_uint32 incomingBandwidth
Definition: enet.h:367
enet_uint32 data
Definition: enet.h:444
int enet_initialize_with_callbacks(ENetVersion version, const ENetCallbacks *inits)
size_t channelLimit
Definition: enet.h:375
Definition: enet.h:180
enet_uint32 incomingBandwidth
Definition: enet.h:277
enet_uint8 * data
Definition: enet.h:152
ENetPacketFreeCallback freeCallback
Definition: enet.h:154
Definition: enet.h:329
ENetAddress address
Definition: enet.h:366
ENetChecksumCallback checksum
Definition: enet.h:385
ENetVersion enet_linked_version(void)
ENet Unix header.
void * userData
Definition: enet.h:155
void enet_deinitialize(void)
ENet callbacks.
size_t channelCount
Definition: enet.h:276
Definition: list.h:18
Definition: enet.h:148