enet.h 23 KB

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