enet
enet.h
Go to the documentation of this file.
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 "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 11
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 {
118 
122 
123 typedef void (ENET_CALLBACK * ENetPacketFreeCallback) (struct _ENetPacket *);
124 
144 typedef struct _ENetPacket
145 {
146  size_t referenceCount;
149  size_t dataLength;
150  ENetPacketFreeCallback freeCallback;
151  void * userData;
152 } ENetPacket;
153 
154 typedef struct _ENetAcknowledgement
155 {
156  ENetListNode acknowledgementList;
157  enet_uint32 sentTime;
158  ENetProtocol command;
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;
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;
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 
213  ENET_PEER_DEFAULT_ROUND_TRIP_TIME = 500,
214  ENET_PEER_DEFAULT_PACKET_THROTTLE = 32,
215  ENET_PEER_PACKET_THROTTLE_SCALE = 32,
216  ENET_PEER_PACKET_THROTTLE_COUNTER = 7,
217  ENET_PEER_PACKET_THROTTLE_ACCELERATION = 2,
218  ENET_PEER_PACKET_THROTTLE_DECELERATION = 2,
219  ENET_PEER_PACKET_THROTTLE_INTERVAL = 5000,
220  ENET_PEER_PACKET_LOSS_SCALE = (1 << 16),
221  ENET_PEER_PACKET_LOSS_INTERVAL = 10000,
222  ENET_PEER_WINDOW_SIZE_SCALE = 64 * 1024,
223  ENET_PEER_TIMEOUT_LIMIT = 32,
224  ENET_PEER_TIMEOUT_MINIMUM = 5000,
225  ENET_PEER_TIMEOUT_MAXIMUM = 30000,
226  ENET_PEER_PING_INTERVAL = 500,
227  ENET_PEER_UNSEQUENCED_WINDOWS = 64,
228  ENET_PEER_UNSEQUENCED_WINDOW_SIZE = 1024,
229  ENET_PEER_FREE_UNSEQUENCED_WINDOWS = 32,
230  ENET_PEER_RELIABLE_WINDOWS = 16,
231  ENET_PEER_RELIABLE_WINDOW_SIZE = 0x1000,
232  ENET_PEER_FREE_RELIABLE_WINDOWS = 8
233 };
234 
235 typedef struct _ENetChannel
236 {
237  enet_uint16 outgoingReliableSequenceNumber;
238  enet_uint16 outgoingUnreliableSequenceNumber;
239  enet_uint16 usedReliableWindows;
240  enet_uint16 reliableWindows [ENET_PEER_RELIABLE_WINDOWS];
241  enet_uint16 incomingReliableSequenceNumber;
242  enet_uint16 incomingUnreliableSequenceNumber;
243  ENetList incomingReliableCommands;
244  ENetList incomingUnreliableCommands;
245 } ENetChannel;
246 
252 typedef struct _ENetPeer
253 {
254  ENetListNode dispatchList;
255  struct _ENetHost * host;
256  enet_uint16 outgoingPeerID;
257  enet_uint16 incomingPeerID;
258  enet_uint32 connectID;
259  enet_uint8 outgoingSessionID;
260  enet_uint8 incomingSessionID;
262  void * data;
263  ENetPeerState state;
264  ENetChannel * channels;
265  size_t channelCount;
268  enet_uint32 incomingBandwidthThrottleEpoch;
269  enet_uint32 outgoingBandwidthThrottleEpoch;
270  enet_uint32 incomingDataTotal;
271  enet_uint32 outgoingDataTotal;
272  enet_uint32 lastSendTime;
273  enet_uint32 lastReceiveTime;
274  enet_uint32 nextTimeout;
275  enet_uint32 earliestTimeout;
276  enet_uint32 packetLossEpoch;
277  enet_uint32 packetsSent;
278  enet_uint32 packetsLost;
280  enet_uint32 packetLossVariance;
281  enet_uint32 packetThrottle;
282  enet_uint32 packetThrottleLimit;
283  enet_uint32 packetThrottleCounter;
284  enet_uint32 packetThrottleEpoch;
285  enet_uint32 packetThrottleAcceleration;
286  enet_uint32 packetThrottleDeceleration;
287  enet_uint32 packetThrottleInterval;
288  enet_uint32 pingInterval;
289  enet_uint32 timeoutLimit;
290  enet_uint32 timeoutMinimum;
291  enet_uint32 timeoutMaximum;
292  enet_uint32 lastRoundTripTime;
293  enet_uint32 lowestRoundTripTime;
294  enet_uint32 lastRoundTripTimeVariance;
295  enet_uint32 highestRoundTripTimeVariance;
297  enet_uint32 roundTripTimeVariance;
298  enet_uint32 mtu;
299  enet_uint32 windowSize;
300  enet_uint32 reliableDataInTransit;
301  enet_uint16 outgoingReliableSequenceNumber;
302  ENetList acknowledgements;
303  ENetList sentReliableCommands;
304  ENetList sentUnreliableCommands;
305  ENetList outgoingReliableCommands;
306  ENetList outgoingUnreliableCommands;
307  ENetList dispatchedCommands;
308  int needsDispatch;
309  enet_uint16 incomingUnsequencedGroup;
310  enet_uint16 outgoingUnsequencedGroup;
311  enet_uint32 unsequencedWindow [ENET_PEER_UNSEQUENCED_WINDOW_SIZE / 32];
312  enet_uint32 eventData;
313 } ENetPeer;
314 
317 typedef struct _ENetCompressor
318 {
320  void * context;
322  size_t (ENET_CALLBACK * compress) (void * context, const ENetBuffer * inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 * outData, size_t outLimit);
324  size_t (ENET_CALLBACK * decompress) (void * context, const enet_uint8 * inData, size_t inLimit, enet_uint8 * outData, size_t outLimit);
326  void (ENET_CALLBACK * destroy) (void * context);
328 
330 typedef enet_uint32 (ENET_CALLBACK * ENetChecksumCallback) (const ENetBuffer * buffers, size_t bufferCount);
331 
333 typedef int (ENET_CALLBACK * ENetInterceptCallback) (struct _ENetHost * host, struct _ENetEvent * event);
334 
351 typedef struct _ENetHost
352 {
353  ENetSocket socket;
357  enet_uint32 bandwidthThrottleEpoch;
358  enet_uint32 mtu;
359  enet_uint32 randomSeed;
360  int recalculateBandwidthLimits;
362  size_t peerCount;
363  size_t channelLimit;
364  enet_uint32 serviceTime;
365  ENetList dispatchQueue;
366  int continueSending;
367  size_t packetSize;
368  enet_uint16 headerFlags;
369  ENetProtocol commands [ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS];
370  size_t commandCount;
371  ENetBuffer buffers [ENET_BUFFER_MAXIMUM];
372  size_t bufferCount;
373  ENetChecksumCallback checksum;
374  ENetCompressor compressor;
375  enet_uint8 packetData [2][ENET_PROTOCOL_MAXIMUM_MTU];
376  ENetAddress receivedAddress;
377  enet_uint8 * receivedData;
378  size_t receivedDataLength;
383  ENetInterceptCallback intercept;
384  size_t connectedPeers;
385  size_t bandwidthLimitedPeers;
386  size_t duplicatePeers;
387 } ENetHost;
388 
392 typedef enum _ENetEventType
393 {
396 
401 
410 
418 } ENetEventType;
419 
425 typedef struct _ENetEvent
426 {
432 } ENetEvent;
433 
443 ENET_API int enet_initialize (void);
444 
452 ENET_API int enet_initialize_with_callbacks (ENetVersion version, const ENetCallbacks * inits);
453 
458 ENET_API void enet_deinitialize (void);
459 
464 ENET_API ENetVersion enet_linked_version (void);
465 
474 ENET_API enet_uint32 enet_time_get (void);
478 ENET_API void enet_time_set (enet_uint32);
479 
483 ENET_API ENetSocket enet_socket_create (ENetSocketType);
484 ENET_API int enet_socket_bind (ENetSocket, const ENetAddress *);
485 ENET_API int enet_socket_get_address (ENetSocket, ENetAddress *);
486 ENET_API int enet_socket_listen (ENetSocket, int);
487 ENET_API ENetSocket enet_socket_accept (ENetSocket, ENetAddress *);
488 ENET_API int enet_socket_connect (ENetSocket, const ENetAddress *);
489 ENET_API int enet_socket_send (ENetSocket, const ENetAddress *, const ENetBuffer *, size_t);
490 ENET_API int enet_socket_receive (ENetSocket, ENetAddress *, ENetBuffer *, size_t);
491 ENET_API int enet_socket_wait (ENetSocket, enet_uint32 *, enet_uint32);
492 ENET_API int enet_socket_set_option (ENetSocket, ENetSocketOption, int);
493 ENET_API int enet_socket_get_option (ENetSocket, ENetSocketOption, int *);
494 ENET_API int enet_socket_shutdown (ENetSocket, ENetSocketShutdown);
495 ENET_API void enet_socket_destroy (ENetSocket);
496 ENET_API int enet_socketset_select (ENetSocket, ENetSocketSet *, ENetSocketSet *, enet_uint32);
497 
511 ENET_API int enet_address_set_host (ENetAddress * address, const char * hostName);
512 
521 ENET_API int enet_address_get_host_ip (const ENetAddress * address, char * hostName, size_t nameLength);
522 
531 ENET_API int enet_address_get_host (const ENetAddress * address, char * hostName, size_t nameLength);
532 
535 ENET_API ENetPacket * enet_packet_create (const void *, size_t, enet_uint32);
536 ENET_API void enet_packet_destroy (ENetPacket *);
537 ENET_API int enet_packet_resize (ENetPacket *, size_t);
538 ENET_API enet_uint32 enet_crc32 (const ENetBuffer *, size_t);
539 
540 ENET_API ENetHost * enet_host_create (const ENetAddress *, size_t, size_t, enet_uint32, enet_uint32);
541 ENET_API void enet_host_destroy (ENetHost *);
542 ENET_API ENetPeer * enet_host_connect (ENetHost *, const ENetAddress *, size_t, enet_uint32);
543 ENET_API int enet_host_check_events (ENetHost *, ENetEvent *);
544 ENET_API int enet_host_service (ENetHost *, ENetEvent *, enet_uint32);
545 ENET_API void enet_host_flush (ENetHost *);
546 ENET_API void enet_host_broadcast (ENetHost *, enet_uint8, ENetPacket *);
547 ENET_API void enet_host_compress (ENetHost *, const ENetCompressor *);
548 ENET_API int enet_host_compress_with_range_coder (ENetHost * host);
549 ENET_API void enet_host_channel_limit (ENetHost *, size_t);
551 extern void enet_host_bandwidth_throttle (ENetHost *);
552 extern enet_uint32 enet_host_random_seed (void);
553 
554 ENET_API int enet_peer_send (ENetPeer *, enet_uint8, ENetPacket *);
555 ENET_API ENetPacket * enet_peer_receive (ENetPeer *, enet_uint8 * channelID);
556 ENET_API void enet_peer_ping (ENetPeer *);
557 ENET_API void enet_peer_ping_interval (ENetPeer *, enet_uint32);
559 ENET_API void enet_peer_reset (ENetPeer *);
560 ENET_API void enet_peer_disconnect (ENetPeer *, enet_uint32);
564 extern int enet_peer_throttle (ENetPeer *, enet_uint32);
565 extern void enet_peer_reset_queues (ENetPeer *);
566 extern void enet_peer_setup_outgoing_command (ENetPeer *, ENetOutgoingCommand *);
567 extern ENetOutgoingCommand * enet_peer_queue_outgoing_command (ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32, enet_uint16);
568 extern ENetIncomingCommand * enet_peer_queue_incoming_command (ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32);
569 extern ENetAcknowledgement * enet_peer_queue_acknowledgement (ENetPeer *, const ENetProtocol *, enet_uint16);
570 extern void enet_peer_dispatch_incoming_unreliable_commands (ENetPeer *, ENetChannel *);
571 extern void enet_peer_dispatch_incoming_reliable_commands (ENetPeer *, ENetChannel *);
572 extern void enet_peer_on_connect (ENetPeer *);
573 extern void enet_peer_on_disconnect (ENetPeer *);
574 
575 ENET_API void * enet_range_coder_create (void);
576 ENET_API void enet_range_coder_destroy (void *);
577 ENET_API size_t enet_range_coder_compress (void *, const ENetBuffer *, size_t, size_t, enet_uint8 *, size_t);
578 ENET_API size_t enet_range_coder_decompress (void *, const enet_uint8 *, size_t, enet_uint8 *, size_t);
579 
580 extern size_t enet_protocol_command_size (enet_uint8);
581 
582 #ifdef __cplusplus
583 }
584 #endif
585 
586 #endif /* __ENET_ENET_H__ */
587 
ENET_API void enet_host_flush(ENetHost *)
Sends any queued packets on the host specified to its designated peers.
Definition: protocol.c:1762
ENetPeer * peers
array of peers allocated for this host
Definition: enet.h:361
enet_uint32 totalSentData
total data sent, user should reset to 0 as needed to prevent overflow
Definition: enet.h:379
whether the packet has been sent from all queues it has been entered into
Definition: enet.h:120
ENetAddress address
Internet address of the peer.
Definition: enet.h:261
type definitions for ENet
An ENet packet compressor for compressing UDP packets before socket sends or receives.
Definition: enet.h:317
ENET_API void enet_peer_ping_interval(ENetPeer *, enet_uint32)
Sets the interval at which pings will be sent to a peer.
Definition: peer.c:455
ENetVersion enet_linked_version(void)
Gives the linked version of the ENet library.
Definition: callbacks.c:32
ENET_API void enet_peer_timeout(ENetPeer *, enet_uint32, enet_uint32, enet_uint32)
Sets the timeout parameters for a peer.
Definition: peer.c:478
ENET_API enet_uint32 enet_time_get(void)
Returns the wall-time in milliseconds.
Definition: unix.c:79
ENET_API int enet_host_check_events(ENetHost *, ENetEvent *)
Checks for any queued events on the host and dispatches one if available.
Definition: protocol.c:1779
enet_uint32 totalSentPackets
total UDP packets sent, user should reset to 0 as needed to prevent overflow
Definition: enet.h:380
int enet_host_compress_with_range_coder(ENetHost *host)
Sets the packet compressor the host should use to the default range coder.
Definition: compress.c:638
packet must be received by the target peer and resend attempts should be made until the packet is del...
Definition: enet.h:108
void * data
Application private data, may be freely modified.
Definition: enet.h:262
Portable internet address structure.
Definition: enet.h:89
Definition: list.h:18
ENET_API void enet_packet_destroy(ENetPacket *)
Destroys the packet and deallocates its data.
Definition: packet.c:57
ENET_API void enet_peer_disconnect_later(ENetPeer *, enet_uint32)
Request a disconnection from a peer, but only after all queued outgoing packets are sent...
Definition: peer.c:567
unsigned int enet_uint32
unsigned 32-bit type
Definition: types.h:10
ENET_API int enet_packet_resize(ENetPacket *, size_t)
Attempts to resize the data in the packet to length specified in the dataLength parameter.
Definition: packet.c:77
ENetPeer * enet_host_connect(ENetHost *host, const ENetAddress *address, size_t channelCount, enet_uint32 data)
Initiates a connection to a foreign host.
Definition: host.c:172
ENetAddress address
Internet address of the host.
Definition: enet.h:354
packet will not be sequenced with other packets not supported for reliable packets ...
Definition: enet.h:112
ENetChecksumCallback checksum
callback the user can set to enable packet checksums for this host
Definition: enet.h:373
a packet has been received from a peer.
Definition: enet.h:417
ENET_API void enet_peer_ping(ENetPeer *)
Sends a ping request to a peer.
Definition: peer.c:432
void enet_host_destroy(ENetHost *host)
Destroys the host and all resources associated with it.
Definition: host.c:139
enet_uint32 totalReceivedData
total data received, user should reset to 0 as needed to prevent overflow
Definition: enet.h:381
struct _ENetPacket ENetPacket
ENet packet structure.
size_t channelCount
Number of channels allocated for communication with peer.
Definition: enet.h:265
ENET_API int enet_address_get_host(const ENetAddress *address, char *hostName, size_t nameLength)
Attempts to do a reverse lookup of the host field in the address parameter.
Definition: unix.c:149
size_t channelLimit
maximum number of channels allowed for connected peers
Definition: enet.h:363
size_t referenceCount
internal use only
Definition: enet.h:146
enet_uint32 flags
bitwise-or of ENetPacketFlag constants
Definition: enet.h:147
ENet protocol.
enet_uint8 * data
allocated data for packet
Definition: enet.h:148
size_t duplicatePeers
optional number of allowed peers from duplicate IPs, defaults to ENET_PROTOCOL_MAXIMUM_PEER_ID ...
Definition: enet.h:386
ENET_API ENetPacket * enet_packet_create(const void *, size_t, enet_uint32)
Creates a packet that may be sent to a peer.
Definition: packet.c:20
ENET_API int enet_host_service(ENetHost *, ENetEvent *, enet_uint32)
Waits for events on the host specified and shuttles packets between the host and its peers...
Definition: protocol.c:1804
enet_uint32 outgoingBandwidth
Upstream bandwidth of the client in bytes/second.
Definition: enet.h:267
Definition: list.h:10
ENetPeer * peer
peer that generated a connect, disconnect or receive event
Definition: enet.h:428
ENetPacketFreeCallback freeCallback
function to be called when the packet is no longer in use
Definition: enet.h:150
Definition: callbacks.h:10
ENET_API ENetPacket * enet_peer_receive(ENetPeer *, enet_uint8 *channelID)
Attempts to dequeue any incoming queued packet.
Definition: peer.c:222
packet will not allocate data, and user must supply it instead
Definition: enet.h:114
Definition: enet.h:154
An ENet event as returned by enet_host_service().
Definition: enet.h:425
void enet_host_broadcast(ENetHost *host, enet_uint8 channelID, ENetPacket *packet)
Queues a packet to be sent to all peers associated with the host.
Definition: host.c:259
enum _ENetEventType ENetEventType
An ENet event type, as specified in ENetEvent.
ENET_API void enet_peer_disconnect(ENetPeer *, enet_uint32)
Request a disconnection from a peer.
Definition: peer.c:524
ENET_API int enet_address_get_host_ip(const ENetAddress *address, char *hostName, size_t nameLength)
Gives the printable form of the ip address specified in the address parameter.
Definition: unix.c:134
enet_uint32 outgoingBandwidth
upstream bandwidth of the host
Definition: enet.h:356
Definition: enet.h:176
Definition: enet.h:235
int enet_initialize_with_callbacks(ENetVersion version, const ENetCallbacks *inits)
Initializes ENet globally and supplies user-overridden callbacks.
Definition: callbacks.c:11
ENet list management.
struct _ENetCompressor ENetCompressor
An ENet packet compressor for compressing UDP packets before socket sends or receives.
ENET_API int enet_address_set_host(ENetAddress *address, const char *hostName)
Attempts to resolve the host named by the parameter hostName and sets the host field in the address p...
Definition: unix.c:99
struct _ENetPeer ENetPeer
An ENet peer which data packets may be sent or received from.
Definition: protocol.h:178
void(ENET_CALLBACK *destroy)(void *context)
Destroys the context when compression is disabled or the host is destroyed.
enum _ENetPacketFlag ENetPacketFlag
Packet flag bit constants.
unsigned short enet_uint16
unsigned 16-bit type
Definition: types.h:9
Definition: enet.h:161
void enet_host_bandwidth_limit(ENetHost *host, enet_uint32 incomingBandwidth, enet_uint32 outgoingBandwidth)
Adjusts the bandwidth limits of a host.
Definition: host.c:318
unsigned char enet_uint8
unsigned 8-bit type
Definition: types.h:8
ENetHost * enet_host_create(const ENetAddress *address, size_t peerCount, size_t channelLimit, enet_uint32 incomingBandwidth, enet_uint32 outgoingBandwidth)
Creates a host for communicating to peers.
Definition: host.c:29
ENET_API void enet_deinitialize(void)
Shuts down ENet globally.
Definition: unix.c:68
An ENet peer which data packets may be sent or received from.
Definition: enet.h:252
struct _ENetAddress ENetAddress
Portable internet address structure.
enet_uint32 incomingBandwidth
downstream bandwidth of the host
Definition: enet.h:355
packet will be fragmented using unreliable (instead of reliable) sends if it exceeds the MTU ...
Definition: enet.h:117
struct _ENetHost ENetHost
An ENet host for communicating with peers.
void enet_host_channel_limit(ENetHost *host, size_t channelLimit)
Limits the maximum allowed channels of future incoming connections.
Definition: host.c:298
enet_uint32 incomingBandwidth
Downstream bandwidth of the client in bytes/second.
Definition: enet.h:266
An ENet host for communicating with peers.
Definition: enet.h:351
enet_uint32 data
data associated with the event, if appropriate
Definition: enet.h:430
void * userData
application private data, may be freely modified
Definition: enet.h:151
struct _ENetEvent ENetEvent
An ENet event as returned by enet_host_service().
ENET_API void enet_time_set(enet_uint32)
Sets the current wall-time in milliseconds.
Definition: unix.c:89
Definition: unix.h:29
void enet_host_compress(ENetHost *host, const ENetCompressor *compressor)
Sets the packet compressor the host should use to compress and decompress packets.
Definition: host.c:282
ENet packet structure.
Definition: enet.h:144
ENet Unix header.
size_t(ENET_CALLBACK *compress)(void *context
Compresses from inBuffers[0:inBufferCount-1], containing inLimit bytes, to outData, outputting at most outLimit bytes.
ENET_API int enet_peer_send(ENetPeer *, enet_uint8, ENetPacket *)
Queues a packet to be sent.
Definition: peer.c:100
size_t dataLength
length of data
Definition: enet.h:149
ENET_API void enet_peer_throttle_configure(ENetPeer *, enet_uint32, enet_uint32, enet_uint32)
Configures throttle parameter for a peer.
Definition: peer.c:43
ENET_API void enet_peer_disconnect_now(ENetPeer *, enet_uint32)
Force an immediate disconnection from a peer.
Definition: peer.c:493
enet_uint8 channelID
channel on the peer that generated the event, if appropriate
Definition: enet.h:429
typedef int(ENET_CALLBACK *ENetInterceptCallback)(struct _ENetHost *host
Callback for intercepting received raw UDP packets.
enet_uint32 totalReceivedPackets
total UDP packets received, user should reset to 0 as needed to prevent overflow
Definition: enet.h:382
a peer has disconnected.
Definition: enet.h:409
void * context
Context data for the compressor.
Definition: enet.h:320
a connection request initiated by enet_host_connect has completed.
Definition: enet.h:400
ENET_API int enet_initialize(void)
Initializes ENet globally.
Definition: unix.c:62
ENET_API void enet_peer_reset(ENetPeer *)
Forcefully disconnects a peer.
Definition: peer.c:370
ENetPacket * packet
packet associated with the event, if appropriate
Definition: enet.h:431
no event occurred within the specified time limit
Definition: enet.h:395
_ENetEventType
An ENet event type, as specified in ENetEvent.
Definition: enet.h:392
_ENetPacketFlag
Packet flag bit constants.
Definition: enet.h:104
ENet callbacks.
enet_uint32 roundTripTime
mean round trip time (RTT), in milliseconds, between sending a reliable packet and receiving its ackn...
Definition: enet.h:296
ENet Win32 header.
ENetInterceptCallback intercept
callback the user can set to intercept received raw UDP packets
Definition: enet.h:383
ENetEventType type
type of the event
Definition: enet.h:427
enet_uint32 packetLoss
mean packet loss of reliable packets as a ratio with respect to the constant ENET_PEER_PACKET_LOSS_SC...
Definition: enet.h:279
size_t peerCount
number of peers allocated for this host
Definition: enet.h:362