enet  v1.3.12
reliable UDP networking library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ENet host functions

Functions

void enet_host_bandwidth_limit (ENetHost *host, enet_uint32 incomingBandwidth, enet_uint32 outgoingBandwidth)
 Adjusts the bandwidth limits of a host. More...
 
void enet_host_bandwidth_throttle (ENetHost *host)
 
void enet_host_broadcast (ENetHost *host, enet_uint8 channelID, ENetPacket *packet)
 Queues a packet to be sent to all peers associated with the host. More...
 
void enet_host_channel_limit (ENetHost *host, size_t channelLimit)
 Limits the maximum allowed channels of future incoming connections. More...
 
int enet_host_check_events (ENetHost *host, ENetEvent *event)
 Checks for any queued events on the host and dispatches one if available. More...
 
void enet_host_compress (ENetHost *host, const ENetCompressor *compressor)
 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...
 
ENetPeerenet_host_connect (ENetHost *host, const ENetAddress *address, size_t channelCount, enet_uint32 data)
 Initiates a connection to a foreign host. More...
 
ENetHostenet_host_create (const ENetAddress *address, size_t peerCount, size_t channelLimit, enet_uint32 incomingBandwidth, enet_uint32 outgoingBandwidth)
 Creates a host for communicating to peers. More...
 
void enet_host_destroy (ENetHost *host)
 Destroys the host and all resources associated with it. More...
 
void enet_host_flush (ENetHost *host)
 Sends any queued packets on the host specified to its designated peers. More...
 
int enet_host_service (ENetHost *host, ENetEvent *event, enet_uint32 timeout)
 Waits for events on the host specified and shuttles packets between the host and its peers. More...
 

Detailed Description

Function Documentation

void enet_host_bandwidth_limit ( ENetHost host,
enet_uint32  incomingBandwidth,
enet_uint32  outgoingBandwidth 
)

#include <host.c>

Adjusts the bandwidth limits of a host.

Parameters
hosthost to adjust
incomingBandwidthnew incoming bandwidth
outgoingBandwidthnew outgoing bandwidth
Remarks
the incoming and outgoing bandwidth parameters are identical in function to those specified in enet_host_create().
void enet_host_broadcast ( ENetHost host,
enet_uint8  channelID,
ENetPacket packet 
)

#include <host.c>

Queues a packet to be sent to all peers associated with the host.

Parameters
hosthost on which to broadcast the packet
channelIDchannel on which to broadcast
packetpacket to broadcast

References enet_packet_destroy(), enet_peer_send(), and ENET_PEER_STATE_CONNECTED.

Here is the call graph for this function:

void enet_host_channel_limit ( ENetHost host,
size_t  channelLimit 
)

#include <host.c>

Limits the maximum allowed channels of future incoming connections.

Parameters
hosthost to limit
channelLimitthe maximum number of channels allowed; if 0, then this is equivalent to ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT

References ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT, and ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT.

int enet_host_check_events ( ENetHost host,
ENetEvent event 
)

#include <protocol.c>

Checks for any queued events on the host and dispatches one if available.

Parameters
hosthost to check for events
eventan event structure where event details will be placed if available
Return values
>0 if an event was dispatched
0if no events are available
<0 on failure

References ENET_EVENT_TYPE_NONE.

void enet_host_compress ( ENetHost host,
const ENetCompressor compressor 
)

#include <host.c>

Sets the packet compressor the host should use to compress and decompress packets.

Parameters
hosthost to enable or disable compression for
compressorcallbacks for for the packet compressor; if NULL, then compression is disabled

References _ENetCompressor::context.

Referenced by enet_host_compress_with_range_coder().

Here is the caller graph for this function:

int enet_host_compress_with_range_coder ( ENetHost host)

#include <compress.c>

Sets the packet compressor the host should use to the default range coder.

Parameters
hosthost to enable the range coder for
Returns
0 on success, < 0 on failure

References _ENetCompressor::context, enet_host_compress(), enet_range_coder_compress(), enet_range_coder_create(), enet_range_coder_decompress(), and enet_range_coder_destroy().

Here is the call graph for this function:

ENetPeer* enet_host_connect ( ENetHost host,
const ENetAddress address,
size_t  channelCount,
enet_uint32  data 
)

#include <host.c>

Initiates a connection to a foreign host.

Parameters
hosthost seeking the connection
addressdestination for the connection
channelCountnumber of channels to allocate
datauser data supplied to the receiving host
Returns
a peer representing the foreign host on success, NULL on failure
Remarks
The peer returned will have not completed the connection until enet_host_service() notifies of an ENET_EVENT_TYPE_CONNECT event for the peer.

References _ENetProtocolConnect::channelCount, _ENetProtocolCommandHeader::channelID, _ENetProtocolCommandHeader::command, _ENetProtocol::connect, _ENetProtocolConnect::connectID, _ENetProtocolConnect::data, ENET_HOST_TO_NET_16, ENET_HOST_TO_NET_32, enet_list_clear(), enet_malloc(), enet_peer_queue_outgoing_command(), ENET_PEER_STATE_CONNECTING, ENET_PEER_STATE_DISCONNECTED, ENET_PEER_WINDOW_SIZE_SCALE, ENET_PROTOCOL_COMMAND_CONNECT, ENET_PROTOCOL_COMMAND_FLAG_ACKNOWLEDGE, ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT, ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE, ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT, ENET_PROTOCOL_MINIMUM_WINDOW_SIZE, _ENetProtocol::header, _ENetProtocolConnect::incomingBandwidth, _ENetProtocolConnect::incomingSessionID, _ENetProtocolConnect::mtu, _ENetProtocolConnect::outgoingBandwidth, _ENetProtocolConnect::outgoingPeerID, _ENetProtocolConnect::outgoingSessionID, _ENetProtocolConnect::packetThrottleAcceleration, _ENetProtocolConnect::packetThrottleDeceleration, _ENetProtocolConnect::packetThrottleInterval, and _ENetProtocolConnect::windowSize.

Here is the call graph for this function:

ENetHost* enet_host_create ( const ENetAddress address,
size_t  peerCount,
size_t  channelLimit,
enet_uint32  incomingBandwidth,
enet_uint32  outgoingBandwidth 
)

#include <host.c>

Creates a host for communicating to peers.

Parameters
addressthe address at which other peers may connect to this host. If NULL, then no peers may connect to the host.
peerCountthe maximum number of peers that should be allocated for the host.
channelLimitthe maximum number of channels allowed; if 0, then this is equivalent to ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT
incomingBandwidthdownstream bandwidth of the host in bytes/second; if 0, ENet will assume unlimited bandwidth.
outgoingBandwidthupstream bandwidth of the host in bytes/second; if 0, ENet will assume unlimited bandwidth.
Returns
the host on success and NULL on failure
Remarks
ENet will strategically drop packets on specific sides of a connection between hosts to ensure the host's bandwidth is not overwhelmed. The bandwidth parameters also determine the window size of a connection which limits the amount of reliable packets that may be in transit at any given time.

References enet_free(), ENET_HOST_ANY, ENET_HOST_DEFAULT_MAXIMUM_PACKET_SIZE, ENET_HOST_DEFAULT_MAXIMUM_WAITING_DATA, ENET_HOST_DEFAULT_MTU, enet_host_random_seed(), ENET_HOST_RECEIVE_BUFFER_SIZE, ENET_HOST_SEND_BUFFER_SIZE, enet_list_clear(), enet_malloc(), enet_peer_reset(), ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT, ENET_PROTOCOL_MAXIMUM_PEER_ID, ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT, enet_socket_bind(), enet_socket_create(), enet_socket_destroy(), enet_socket_get_address(), ENET_SOCKET_NULL, enet_socket_set_option(), ENET_SOCKET_TYPE_DATAGRAM, ENET_SOCKOPT_BROADCAST, ENET_SOCKOPT_NONBLOCK, ENET_SOCKOPT_RCVBUF, and ENET_SOCKOPT_SNDBUF.

Here is the call graph for this function:

void enet_host_destroy ( ENetHost host)

#include <host.c>

Destroys the host and all resources associated with it.

Parameters
hostpointer to the host to destroy

References enet_free(), enet_peer_reset(), and enet_socket_destroy().

Here is the call graph for this function:

void enet_host_flush ( ENetHost host)

#include <protocol.c>

Sends any queued packets on the host specified to its designated peers.

Parameters
hosthost to flush
Remarks
this function need only be used in circumstances where one wishes to send queued packets earlier than in a call to enet_host_service().

References enet_time_get().

Referenced by enet_peer_disconnect(), and enet_peer_disconnect_now().

Here is the call graph for this function:

Here is the caller graph for this function:

int enet_host_service ( ENetHost host,
ENetEvent event,
enet_uint32  timeout 
)

#include <protocol.c>

Waits for events on the host specified and shuttles packets between the host and its peers.

Parameters
hosthost to service
eventan event structure where event details will be placed if one occurs if event == NULL then no events will be delivered
timeoutnumber of milliseconds that ENet should wait for events
Return values
>0 if an event occurred within the specified time limit
0if no event occurred
<0 on failure
Remarks
enet_host_service should be called fairly regularly for adequate performance

References ENET_EVENT_TYPE_NONE, enet_host_bandwidth_throttle(), ENET_HOST_BANDWIDTH_THROTTLE_INTERVAL, enet_socket_wait(), ENET_SOCKET_WAIT_INTERRUPT, ENET_SOCKET_WAIT_RECEIVE, ENET_TIME_DIFFERENCE, enet_time_get(), and ENET_TIME_GREATER_EQUAL.

Here is the call graph for this function: