ENet: include/enet/enet.h File Reference

ENet v1.3.18 Reliable UDP networking library

Data Structures | Macros | Typedefs | Enumerations | Functions
enet.h File Reference

ENet public header file. More...

`#include <stdlib.h>`
`#include "enet/unix.h"`
`#include "enet/types.h"`
`#include "enet/protocol.h"`
`#include "enet/list.h"`
`#include "enet/callbacks.h"`

## Data Structures
struct | ENetAcknowledgement
struct | ENetAddress
| Portable internet address structure. More...
struct | ENetChannel
struct | ENetCompressor
| An ENet packet compressor for compressing UDP packets before socket sends or receives. More...
struct | ENetEvent
| An ENet event as returned by enet_host_service(). More...
struct | ENetHost
| An ENet host for communicating with peers. More...
struct | ENetIncomingCommand
struct | ENetOutgoingCommand
struct | ENetPacket
| ENet packet structure. More...
struct | ENetPeer
| An ENet peer which data packets may be sent or received from. More...

## Macros
#define | ENET_BUFFER_MAXIMUM (1 + 2 * ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS)
#define | ENET_HOST_ANY 0
#define | ENET_HOST_BROADCAST 0xFFFFFFFFU
#define | ENET_PORT_ANY 0
#define | ENET_VERSION ENET_VERSION_CREATE(ENET_VERSION_MAJOR, ENET_VERSION_MINOR, ENET_VERSION_PATCH)
#define | ENET_VERSION_CREATE(major, minor, patch) (((major)<<16) | ((minor)<<8) | (patch))
#define | ENET_VERSION_GET_MAJOR(version) (((version)>>16)&0xFF)
#define | ENET_VERSION_GET_MINOR(version) (((version)>>8)&0xFF)
#define | ENET_VERSION_GET_PATCH(version) ((version)&0xFF)
#define | ENET_VERSION_MAJOR 1
#define | ENET_VERSION_MINOR 3
#define | ENET_VERSION_PATCH 18

## Typedefs
typedef enet_uint32(* | ENetChecksumCallback) (const ENetBuffer *buffers, size_t bufferCount)
| Callback that computes the checksum of the data held in buffers[0:bufferCount-1]. More...
typedef int(* | ENetInterceptCallback) (struct _ENetHost *host, struct _ENetEvent *event)
| Callback for intercepting received raw UDP packets. More...
typedef void(* | ENetPacketFreeCallback) (struct _ENetPacket *)
typedef enet_uint32 | ENetVersion

## Enumerations
enum | { ENET_HOST_RECEIVE_BUFFER_SIZE = 256 * 1024 , ENET_HOST_SEND_BUFFER_SIZE = 256 * 1024 , ENET_HOST_BANDWIDTH_THROTTLE_INTERVAL = 1000 , ENET_HOST_DEFAULT_MTU = 1392 , ENET_HOST_DEFAULT_MAXIMUM_PACKET_SIZE = 32 * 1024 * 1024 , ENET_HOST_DEFAULT_MAXIMUM_WAITING_DATA = 32 * 1024 * 1024 , ENET_PEER_DEFAULT_ROUND_TRIP_TIME = 500 , ENET_PEER_DEFAULT_PACKET_THROTTLE = 32 , ENET_PEER_PACKET_THROTTLE_SCALE = 32 , ENET_PEER_PACKET_THROTTLE_COUNTER = 7 , ENET_PEER_PACKET_THROTTLE_ACCELERATION = 2 , ENET_PEER_PACKET_THROTTLE_DECELERATION = 2 , ENET_PEER_PACKET_THROTTLE_INTERVAL = 5000 , ENET_PEER_PACKET_LOSS_SCALE = (1 << 16) , ENET_PEER_PACKET_LOSS_INTERVAL = 10000 , ENET_PEER_WINDOW_SIZE_SCALE = 64 * 1024 , ENET_PEER_TIMEOUT_LIMIT = 32 , ENET_PEER_TIMEOUT_MINIMUM = 5000 , ENET_PEER_TIMEOUT_MAXIMUM = 30000 , ENET_PEER_PING_INTERVAL = 500 , ENET_PEER_UNSEQUENCED_WINDOWS = 64 , ENET_PEER_UNSEQUENCED_WINDOW_SIZE = 1024 , ENET_PEER_FREE_UNSEQUENCED_WINDOWS = 32 , ENET_PEER_RELIABLE_WINDOWS = 16 , ENET_PEER_RELIABLE_WINDOW_SIZE = 0x1000 , ENET_PEER_FREE_RELIABLE_WINDOWS = 8 }
enum | ENetEventType { ENET_EVENT_TYPE_NONE = 0 , ENET_EVENT_TYPE_CONNECT = 1 , ENET_EVENT_TYPE_DISCONNECT = 2 , ENET_EVENT_TYPE_RECEIVE = 3 }
| An ENet event type, as specified in ENetEvent. More...
enum | ENetPacketFlag { ENET_PACKET_FLAG_RELIABLE = (1 << 0) , ENET_PACKET_FLAG_UNSEQUENCED = (1 << 1) , ENET_PACKET_FLAG_NO_ALLOCATE = (1 << 2) , ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT = (1 << 3) , ENET_PACKET_FLAG_SENT = (1<<8) }
| Packet flag bit constants. More...
enum | ENetPeerFlag { ENET_PEER_FLAG_NEEDS_DISPATCH = (1 << 0) , ENET_PEER_FLAG_CONTINUE_SENDING = (1 << 1) }
enum | ENetPeerState { ENET_PEER_STATE_DISCONNECTED = 0 , ENET_PEER_STATE_CONNECTING = 1 , ENET_PEER_STATE_ACKNOWLEDGING_CONNECT = 2 , ENET_PEER_STATE_CONNECTION_PENDING = 3 , ENET_PEER_STATE_CONNECTION_SUCCEEDED = 4 , ENET_PEER_STATE_CONNECTED = 5 , ENET_PEER_STATE_DISCONNECT_LATER = 6 , ENET_PEER_STATE_DISCONNECTING = 7 , ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT = 8 , ENET_PEER_STATE_ZOMBIE = 9 }
enum | ENetSocketOption { ENET_SOCKOPT_NONBLOCK = 1 , ENET_SOCKOPT_BROADCAST = 2 , ENET_SOCKOPT_RCVBUF = 3 , ENET_SOCKOPT_SNDBUF = 4 , ENET_SOCKOPT_REUSEADDR = 5 , ENET_SOCKOPT_RCVTIMEO = 6 , ENET_SOCKOPT_SNDTIMEO = 7 , ENET_SOCKOPT_ERROR = 8 , ENET_SOCKOPT_NODELAY = 9 , ENET_SOCKOPT_TTL = 10 }
enum | ENetSocketShutdown { ENET_SOCKET_SHUTDOWN_READ = 0 , ENET_SOCKET_SHUTDOWN_WRITE = 1 , ENET_SOCKET_SHUTDOWN_READ_WRITE = 2 }
enum | ENetSocketType { ENET_SOCKET_TYPE_STREAM = 1 , ENET_SOCKET_TYPE_DATAGRAM = 2 }
enum | ENetSocketWait { ENET_SOCKET_WAIT_NONE = 0 , ENET_SOCKET_WAIT_SEND = (1 << 0) , ENET_SOCKET_WAIT_RECEIVE = (1 << 1) , ENET_SOCKET_WAIT_INTERRUPT = (1 << 2) }

## Functions
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. More...
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. More...
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 parameter if successful. More...
int | enet_address_set_host_ip (ENetAddress *address, const char *hostName)
| Attempts to parse the printable form of the IP address in the parameter hostName and sets the host field in the address parameter if successful. More...
enet_uint32 | enet_crc32 (const ENetBuffer *, size_t)
void | enet_deinitialize (void)
| Shuts down ENet globally. More...
void | enet_host_bandwidth_limit (ENetHost *, enet_uint32, enet_uint32)
| Adjusts the bandwidth limits of a host. More...
void | enet_host_bandwidth_throttle (ENetHost *)
void | enet_host_broadcast (ENetHost *, enet_uint8, ENetPacket *)
| Queues a packet to be sent to all peers associated with the host. More...
void | enet_host_channel_limit (ENetHost *, size_t)
| Limits the maximum allowed channels of future incoming connections. More...
int | enet_host_check_events (ENetHost *, ENetEvent *)
| Checks for any queued events on the host and dispatches one if available. More...
void | enet_host_compress (ENetHost *, const ENetCompressor *)
| Sets the packet compressor the host should use to compress and decompress packets. More...
int | enet_host_compress_with_range_coder (ENetHost *host)
| Sets the packet compressor the host should use to the default range coder. More...
ENetPeer * | enet_host_connect (ENetHost *, const ENetAddress *, size_t, enet_uint32)
| Initiates a connection to a foreign host. More...
ENetHost * | enet_host_create (const ENetAddress *, size_t, size_t, enet_uint32, enet_uint32)
| Creates a host for communicating to peers. More...
void | enet_host_destroy (ENetHost *)
| Destroys the host and all resources associated with it. More...
void | enet_host_flush (ENetHost *)
| Sends any queued packets on the host specified to its designated peers. More...
enet_uint32 | enet_host_random (ENetHost *)
enet_uint32 | enet_host_random_seed (void)
int | enet_host_service (ENetHost *, ENetEvent *, enet_uint32)
| Waits for events on the host specified and shuttles packets between the host and its peers. More...
int | enet_initialize (void)
| Initializes ENet globally. More...
int | enet_initialize_with_callbacks (ENetVersion version, const ENetCallbacks *inits)
| Initializes ENet globally and supplies user-overridden callbacks. More...
ENetVersion | enet_linked_version (void)
| Gives the linked version of the ENet library. More...
ENetPacket * | enet_packet_create (const void *, size_t, enet_uint32)
| Creates a packet that may be sent to a peer. More...
void | enet_packet_destroy (ENetPacket *)
| Destroys the packet and deallocates its data. More...
int | enet_packet_resize (ENetPacket *, size_t)
| Attempts to resize the data in the packet to length specified in the dataLength parameter. More...
void | enet_peer_disconnect (ENetPeer *, enet_uint32)
| Request a disconnection from a peer. More...
void | enet_peer_disconnect_later (ENetPeer *, enet_uint32)
| Request a disconnection from a peer, but only after all queued outgoing packets are sent. More...
void | enet_peer_disconnect_now (ENetPeer *, enet_uint32)
| Force an immediate disconnection from a peer. More...
void | enet_peer_dispatch_incoming_reliable_commands (ENetPeer *, ENetChannel *, ENetIncomingCommand *)
void | enet_peer_dispatch_incoming_unreliable_commands (ENetPeer *, ENetChannel *, ENetIncomingCommand *)
int | enet_peer_has_outgoing_commands (ENetPeer *)
void | enet_peer_on_connect (ENetPeer *)
void | enet_peer_on_disconnect (ENetPeer *)
void | enet_peer_ping (ENetPeer *)
| Sends a ping request to a peer. More...
void | enet_peer_ping_interval (ENetPeer *, enet_uint32)
| Sets the interval at which pings will be sent to a peer. More...
ENetAcknowledgement * | enet_peer_queue_acknowledgement (ENetPeer *, const ENetProtocol *, enet_uint16)
ENetIncomingCommand * | enet_peer_queue_incoming_command (ENetPeer *, const ENetProtocol *, const void *, size_t, enet_uint32, enet_uint32)
ENetOutgoingCommand * | enet_peer_queue_outgoing_command (ENetPeer *, const ENetProtocol *, ENetPacket *, enet_uint32, enet_uint16)
ENetPacket * | enet_peer_receive (ENetPeer *, enet_uint8 *channelID)
| Attempts to dequeue any incoming queued packet. More...
void | enet_peer_reset (ENetPeer *)
| Forcefully disconnects a peer. More...
void | enet_peer_reset_queues (ENetPeer *)
int | enet_peer_send (ENetPeer *, enet_uint8, ENetPacket *)
| Queues a packet to be sent. More...
void | enet_peer_setup_outgoing_command (ENetPeer *, ENetOutgoingCommand *)
int | enet_peer_throttle (ENetPeer *, enet_uint32)
void | enet_peer_throttle_configure (ENetPeer *, enet_uint32, enet_uint32, enet_uint32)
| Configures throttle parameter for a peer. More...
void | enet_peer_timeout (ENetPeer *, enet_uint32, enet_uint32, enet_uint32)
| Sets the timeout parameters for a peer. More...
size_t | enet_protocol_command_size (enet_uint8)
size_t | enet_range_coder_compress (void *, const ENetBuffer *, size_t, size_t, enet_uint8 *, size_t)
void * | enet_range_coder_create (void)
size_t | enet_range_coder_decompress (void *, const enet_uint8 *, size_t, enet_uint8 *, size_t)
void | enet_range_coder_destroy (void *)
ENetSocket | enet_socket_accept (ENetSocket, ENetAddress *)
int | enet_socket_bind (ENetSocket, const ENetAddress *)
int | enet_socket_connect (ENetSocket, const ENetAddress *)
ENetSocket | enet_socket_create (ENetSocketType)
void | enet_socket_destroy (ENetSocket)
int | enet_socket_get_address (ENetSocket, ENetAddress *)
int | enet_socket_get_option (ENetSocket, ENetSocketOption, int *)
int | enet_socket_listen (ENetSocket, int)
int | enet_socket_receive (ENetSocket, ENetAddress *, ENetBuffer *, size_t)
int | enet_socket_send (ENetSocket, const ENetAddress *, const ENetBuffer *, size_t)
int | enet_socket_set_option (ENetSocket, ENetSocketOption, int)
int | enet_socket_shutdown (ENetSocket, ENetSocketShutdown)
int | enet_socket_wait (ENetSocket, enet_uint32 *, enet_uint32)
int | enet_socketset_select (ENetSocket, ENetSocketSet *, ENetSocketSet *, enet_uint32)
enet_uint32 | enet_time_get (void)
| Returns the wall-time in milliseconds. More...
void | enet_time_set (enet_uint32)
| Sets the current wall-time in milliseconds. More...

## Detailed Description

ENet public header file.

## Macro Definition Documentation

## ◆ ENET_BUFFER_MAXIMUM

#define ENET_BUFFER_MAXIMUM (1 + 2 * ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS)

## ◆ ENET_HOST_ANY

#define ENET_HOST_ANY 0

## ◆ ENET_HOST_BROADCAST

#define ENET_HOST_BROADCAST 0xFFFFFFFFU

## ◆ ENET_PORT_ANY

#define ENET_PORT_ANY 0

## ◆ ENET_VERSION

#define ENET_VERSION ENET_VERSION_CREATE(ENET_VERSION_MAJOR, ENET_VERSION_MINOR, ENET_VERSION_PATCH)

## ◆ ENET_VERSION_CREATE

#define ENET_VERSION_CREATE | ( |  | major,
|  |  | minor,
|  |  | patch
| ) |  | (((major)<<16) | ((minor)<<8) | (patch))

## ◆ ENET_VERSION_GET_MAJOR

#define ENET_VERSION_GET_MAJOR | ( |  | version | ) | (((version)>>16)&0xFF)

## ◆ ENET_VERSION_GET_MINOR

#define ENET_VERSION_GET_MINOR | ( |  | version | ) | (((version)>>8)&0xFF)

## ◆ ENET_VERSION_GET_PATCH

#define ENET_VERSION_GET_PATCH | ( |  | version | ) | ((version)&0xFF)

## ◆ ENET_VERSION_MAJOR

#define ENET_VERSION_MAJOR 1

## ◆ ENET_VERSION_MINOR

#define ENET_VERSION_MINOR 3

## ◆ ENET_VERSION_PATCH

#define ENET_VERSION_PATCH 18

## Typedef Documentation

## ◆ ENetChecksumCallback

typedef enet_uint32(* ENetChecksumCallback) (const ENetBuffer *buffers, size_t bufferCount)

Callback that computes the checksum of the data held in buffers[0:bufferCount-1].

## ◆ ENetInterceptCallback

typedef int(* ENetInterceptCallback) (struct _ENetHost *host, struct _ENetEvent *event)

Callback for intercepting received raw UDP packets.

Should return 1 to intercept, 0 to ignore, or -1 to propagate an error.

## ◆ ENetPacketFreeCallback

typedef void(* ENetPacketFreeCallback) (struct _ENetPacket *)

## ◆ ENetVersion

typedef enet_uint32 ENetVersion

## Enumeration Type Documentation

## ◆ anonymous enum

anonymous enum

Enumerator
ENET_HOST_RECEIVE_BUFFER_SIZE |
ENET_HOST_SEND_BUFFER_SIZE |
ENET_HOST_BANDWIDTH_THROTTLE_INTERVAL |
ENET_HOST_DEFAULT_MTU |
ENET_HOST_DEFAULT_MAXIMUM_PACKET_SIZE |
ENET_HOST_DEFAULT_MAXIMUM_WAITING_DATA |
ENET_PEER_DEFAULT_ROUND_TRIP_TIME |
ENET_PEER_DEFAULT_PACKET_THROTTLE |
ENET_PEER_PACKET_THROTTLE_SCALE |
ENET_PEER_PACKET_THROTTLE_COUNTER |
ENET_PEER_PACKET_THROTTLE_ACCELERATION |
ENET_PEER_PACKET_THROTTLE_DECELERATION |
ENET_PEER_PACKET_THROTTLE_INTERVAL |
ENET_PEER_PACKET_LOSS_SCALE |
ENET_PEER_PACKET_LOSS_INTERVAL |
ENET_PEER_WINDOW_SIZE_SCALE |
ENET_PEER_TIMEOUT_LIMIT |
ENET_PEER_TIMEOUT_MINIMUM |
ENET_PEER_TIMEOUT_MAXIMUM |
ENET_PEER_PING_INTERVAL |
ENET_PEER_UNSEQUENCED_WINDOWS |
ENET_PEER_UNSEQUENCED_WINDOW_SIZE |
ENET_PEER_FREE_UNSEQUENCED_WINDOWS |
ENET_PEER_RELIABLE_WINDOWS |
ENET_PEER_RELIABLE_WINDOW_SIZE |
ENET_PEER_FREE_RELIABLE_WINDOWS |

## ◆ ENetEventType

enum ENetEventType

An ENet event type, as specified in ENetEvent.

Enumerator
ENET_EVENT_TYPE_NONE | no event occurred within the specified time limit
ENET_EVENT_TYPE_CONNECT | a connection request initiated by enet_host_connect has completed. The peer field contains the peer which successfully connected.
ENET_EVENT_TYPE_DISCONNECT | a peer has disconnected. This event is generated on a successful completion of a disconnect initiated by enet_peer_disconnect, if a peer has timed out, or if a connection request intialized by enet_host_connect has timed out. The peer field contains the peer which disconnected. The data field contains user supplied data describing the disconnection, or 0, if none is available.
ENET_EVENT_TYPE_RECEIVE | a packet has been received from a peer. The peer field specifies the peer which sent the packet. The channelID field specifies the channel number upon which the packet was received. The packet field contains the packet that was received; this packet must be destroyed with enet_packet_destroy after use.

## ◆ ENetPacketFlag

enum ENetPacketFlag

Packet flag bit constants.

The host must be specified in network byte-order, and the port must be in host byte-order. The constant ENET_HOST_ANY may be used to specify the default server host.

See also
  ENetPacket

Enumerator
ENET_PACKET_FLAG_RELIABLE | packet must be received by the target peer and resend attempts should be made until the packet is delivered
ENET_PACKET_FLAG_UNSEQUENCED | packet will not be sequenced with other packets not supported for reliable packets
ENET_PACKET_FLAG_NO_ALLOCATE | packet will not allocate data, and user must supply it instead
ENET_PACKET_FLAG_UNRELIABLE_FRAGMENT | packet will be fragmented using unreliable (instead of reliable) sends if it exceeds the MTU
ENET_PACKET_FLAG_SENT | whether the packet has been sent from all queues it has been entered into

## ◆ ENetPeerFlag

enum ENetPeerFlag

Enumerator
ENET_PEER_FLAG_NEEDS_DISPATCH |
ENET_PEER_FLAG_CONTINUE_SENDING |

## ◆ ENetPeerState

enum ENetPeerState

Enumerator
ENET_PEER_STATE_DISCONNECTED |
ENET_PEER_STATE_CONNECTING |
ENET_PEER_STATE_ACKNOWLEDGING_CONNECT |
ENET_PEER_STATE_CONNECTION_PENDING |
ENET_PEER_STATE_CONNECTION_SUCCEEDED |
ENET_PEER_STATE_CONNECTED |
ENET_PEER_STATE_DISCONNECT_LATER |
ENET_PEER_STATE_DISCONNECTING |
ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT |
ENET_PEER_STATE_ZOMBIE |

## ◆ ENetSocketOption

enum ENetSocketOption

Enumerator
ENET_SOCKOPT_NONBLOCK |
ENET_SOCKOPT_BROADCAST |
ENET_SOCKOPT_RCVBUF |
ENET_SOCKOPT_SNDBUF |
ENET_SOCKOPT_REUSEADDR |
ENET_SOCKOPT_RCVTIMEO |
ENET_SOCKOPT_SNDTIMEO |
ENET_SOCKOPT_ERROR |
ENET_SOCKOPT_NODELAY |
ENET_SOCKOPT_TTL |

## ◆ ENetSocketShutdown

enum ENetSocketShutdown

Enumerator
ENET_SOCKET_SHUTDOWN_READ |
ENET_SOCKET_SHUTDOWN_WRITE |
ENET_SOCKET_SHUTDOWN_READ_WRITE |

## ◆ ENetSocketType

enum ENetSocketType

Enumerator
ENET_SOCKET_TYPE_STREAM |
ENET_SOCKET_TYPE_DATAGRAM |

## ◆ ENetSocketWait

enum ENetSocketWait

Enumerator
ENET_SOCKET_WAIT_NONE |
ENET_SOCKET_WAIT_SEND |
ENET_SOCKET_WAIT_RECEIVE |
ENET_SOCKET_WAIT_INTERRUPT |

## Function Documentation

## ◆ enet_host_random_seed()

enet_uint32 enet_host_random_seed | ( | void |  | ) |

## ◆ enet_protocol_command_size()

size_t enet_protocol_command_size | ( | enet_uint8 | commandNumber | ) |

## ◆ enet_range_coder_compress()

size_t enet_range_coder_compress | ( | void * | context,
|  | const ENetBuffer * | inBuffers,
|  | size_t | inBufferCount,
|  | size_t | inLimit,
|  | enet_uint8 * | outData,
|  | size_t | outLimit
| ) |  |

## ◆ enet_range_coder_create()

void * enet_range_coder_create | ( | void |  | ) |

## ◆ enet_range_coder_decompress()

size_t enet_range_coder_decompress | ( | void * | context,
|  | const enet_uint8 * | inData,
|  | size_t | inLimit,
|  | enet_uint8 * | outData,
|  | size_t | outLimit
| ) |  |

## ◆ enet_range_coder_destroy()

void enet_range_coder_destroy | ( | void * | context | ) |

## ◆ enet_time_get()

enet_uint32 enet_time_get | ( | void |  | ) |

Returns the wall-time in milliseconds.

Its initial value is unspecified unless otherwise set.

## ◆ enet_time_set()

void enet_time_set | ( | enet_uint32 | newTimeBase | ) |

Sets the current wall-time in milliseconds.