enet.h 23 KB

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