enet.h 25 KB

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