enet.h 24 KB

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