enet.h 23 KB

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