ENet.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  1. /*
  2. * Managed C# wrapper for an extended version of ENet
  3. * Copyright (c) 2013 James Bellinger
  4. * Copyright (c) 2016 Nate Shoffner
  5. * Copyright (c) 2018 Stanislav Denisov
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE.
  24. */
  25. using System;
  26. using System.Runtime.InteropServices;
  27. using System.Security;
  28. using System.Text;
  29. namespace ENet {
  30. [Flags]
  31. public enum PacketFlags {
  32. None = 0,
  33. Reliable = 1 << 0,
  34. Unsequenced = 1 << 1,
  35. NoAllocate = 1 << 2,
  36. UnreliableFragment = 1 << 3
  37. }
  38. public enum EventType {
  39. None = 0,
  40. Connect = 1,
  41. Disconnect = 2,
  42. Receive = 3,
  43. Timeout = 4
  44. }
  45. public enum PeerState {
  46. Uninitialized = -1,
  47. Disconnected = 0,
  48. Connecting = 1,
  49. AcknowledgingConnect = 2,
  50. ConnectionPending = 3,
  51. ConnectionSucceeded = 4,
  52. Connected = 5,
  53. DisconnectLater = 6,
  54. Disconnecting = 7,
  55. AcknowledgingDisconnect = 8,
  56. Zombie = 9
  57. }
  58. [StructLayout(LayoutKind.Sequential)]
  59. public struct ENetAddress {
  60. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
  61. public byte[] host;
  62. public ushort port;
  63. }
  64. [StructLayout(LayoutKind.Sequential)]
  65. public struct ENetEvent {
  66. public EventType type;
  67. public IntPtr peer;
  68. public byte channelID;
  69. public uint data;
  70. public IntPtr packet;
  71. }
  72. [StructLayout(LayoutKind.Sequential)]
  73. public struct ENetCallbacks {
  74. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  75. public delegate IntPtr malloc_cb(IntPtr size);
  76. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  77. public delegate void free_cb(IntPtr memory);
  78. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  79. public delegate void no_memory_cb();
  80. public IntPtr malloc, free, no_memory;
  81. }
  82. public struct Address {
  83. private ENetAddress nativeAddress;
  84. internal ENetAddress NativeData {
  85. get {
  86. return nativeAddress;
  87. }
  88. set {
  89. nativeAddress = value;
  90. }
  91. }
  92. public Address(ENetAddress address) {
  93. nativeAddress = address;
  94. }
  95. public ushort Port {
  96. get {
  97. return nativeAddress.port;
  98. }
  99. set {
  100. nativeAddress.port = value;
  101. }
  102. }
  103. public bool SetHost(string hostName) {
  104. if (hostName == null)
  105. throw new ArgumentNullException("hostName");
  106. return Native.enet_address_set_host(ref nativeAddress, Encoding.ASCII.GetBytes(hostName)) == 0;
  107. }
  108. public string GetIP() {
  109. byte[] data = new byte[256];
  110. if (Native.enet_address_get_host_ip(ref nativeAddress, data, (IntPtr)256) == 0)
  111. return Encoding.ASCII.GetString(data);
  112. else
  113. return String.Empty;
  114. }
  115. public string GetName() {
  116. byte[] data = new byte[256];
  117. if (Native.enet_address_get_host(ref nativeAddress, data, (IntPtr)256) == 0)
  118. return Encoding.ASCII.GetString(data);
  119. else
  120. return String.Empty;
  121. }
  122. }
  123. public struct Event {
  124. private ENetEvent nativeEvent;
  125. internal ENetEvent NativeData {
  126. get {
  127. return nativeEvent;
  128. }
  129. set {
  130. nativeEvent = value;
  131. }
  132. }
  133. public Event(ENetEvent @event) {
  134. nativeEvent = @event;
  135. }
  136. public EventType Type {
  137. get {
  138. return nativeEvent.type;
  139. }
  140. }
  141. public Peer Peer {
  142. get {
  143. return new Peer(nativeEvent.peer);
  144. }
  145. }
  146. public byte ChannelID {
  147. get {
  148. return nativeEvent.channelID;
  149. }
  150. }
  151. public uint Data {
  152. get {
  153. return nativeEvent.data;
  154. }
  155. }
  156. public Packet Packet {
  157. get {
  158. return new Packet(nativeEvent.packet);
  159. }
  160. }
  161. }
  162. public struct Packet : IDisposable {
  163. private IntPtr nativePacket;
  164. internal IntPtr NativeData {
  165. get {
  166. return nativePacket;
  167. }
  168. set {
  169. nativePacket = value;
  170. }
  171. }
  172. public Packet(IntPtr packet) {
  173. nativePacket = packet;
  174. }
  175. public void Dispose() {
  176. if (nativePacket != IntPtr.Zero) {
  177. Native.enet_packet_destroy(nativePacket);
  178. nativePacket = IntPtr.Zero;
  179. }
  180. }
  181. public bool IsSet {
  182. get {
  183. return nativePacket != IntPtr.Zero;
  184. }
  185. }
  186. public IntPtr Data {
  187. get {
  188. CheckCreated();
  189. return Native.enet_packet_get_data(nativePacket);
  190. }
  191. }
  192. public int Length {
  193. get {
  194. CheckCreated();
  195. return Native.enet_packet_get_length(nativePacket);
  196. }
  197. }
  198. internal void CheckCreated() {
  199. if (nativePacket == IntPtr.Zero)
  200. throw new InvalidOperationException("Packet not created");
  201. }
  202. public void Create(byte[] data) {
  203. if (data == null)
  204. throw new ArgumentNullException("data");
  205. Create(data, data.Length);
  206. }
  207. public void Create(byte[] data, int length) {
  208. Create(data, length, PacketFlags.None);
  209. }
  210. public void Create(byte[] data, int length, PacketFlags flags) {
  211. if (data == null)
  212. throw new ArgumentNullException("data");
  213. if (length < 0 || length > data.Length)
  214. throw new ArgumentOutOfRangeException();
  215. nativePacket = Native.enet_packet_create(data, (IntPtr)length, flags);
  216. }
  217. public void CopyTo(byte[] array) {
  218. if (array == null)
  219. throw new ArgumentNullException("array");
  220. CopyTo(array, 0, array.Length);
  221. }
  222. public void CopyTo(byte[] array, int offset, int length) {
  223. if (array == null)
  224. throw new ArgumentNullException("array");
  225. if (offset < 0 || length < 0 || length > array.Length - offset)
  226. throw new ArgumentOutOfRangeException();
  227. CheckCreated();
  228. if (length > Length - offset)
  229. throw new ArgumentOutOfRangeException();
  230. if (length > 0)
  231. Marshal.Copy((IntPtr)((Int64)Data + offset), array, offset, length);
  232. }
  233. }
  234. public class Host : IDisposable {
  235. private IntPtr nativeHost;
  236. internal IntPtr NativeData {
  237. get {
  238. return nativeHost;
  239. }
  240. set {
  241. nativeHost = value;
  242. }
  243. }
  244. public void Dispose() {
  245. Dispose(true);
  246. }
  247. protected virtual void Dispose(bool disposing) {
  248. try {
  249. if (nativeHost != IntPtr.Zero) {
  250. Native.enet_host_destroy(nativeHost);
  251. nativeHost = IntPtr.Zero;
  252. }
  253. }
  254. catch { }
  255. }
  256. ~Host() {
  257. Dispose(false);
  258. }
  259. public bool IsSet {
  260. get {
  261. return nativeHost != IntPtr.Zero;
  262. }
  263. }
  264. public uint PeersCount {
  265. get {
  266. return Native.enet_host_get_peers_count(nativeHost);
  267. }
  268. }
  269. public uint PacketsSent {
  270. get {
  271. return Native.enet_host_get_packets_sent(nativeHost);
  272. }
  273. }
  274. public uint PacketsReceived {
  275. get {
  276. return Native.enet_host_get_packets_received(nativeHost);
  277. }
  278. }
  279. public uint BytesSent {
  280. get {
  281. return Native.enet_host_get_bytes_sent(nativeHost);
  282. }
  283. }
  284. public uint BytesReceived {
  285. get {
  286. return Native.enet_host_get_bytes_received(nativeHost);
  287. }
  288. }
  289. internal void CheckCreated() {
  290. if (nativeHost == IntPtr.Zero)
  291. throw new InvalidOperationException("Host not created");
  292. }
  293. private void CheckChannelLimit(int channelLimit) {
  294. if (channelLimit < 0 || channelLimit > Library.maxChannelCount)
  295. throw new ArgumentOutOfRangeException("channelLimit");
  296. }
  297. public void Create() {
  298. Create(null, 1, 0);
  299. }
  300. public void Create(Address? address, int peerLimit) {
  301. Create(address, peerLimit, 0);
  302. }
  303. public void Create(Address? address, int peerLimit, int channelLimit) {
  304. Create(address, peerLimit, channelLimit, 0, 0);
  305. }
  306. public void Create(int peerLimit, int channelLimit, uint incomingBandwidth, uint outgoingBandwidth) {
  307. Create(null, peerLimit, channelLimit, incomingBandwidth, outgoingBandwidth);
  308. }
  309. public void Create(Address? address, int peerLimit, int channelLimit, uint incomingBandwidth, uint outgoingBandwidth) {
  310. if (nativeHost != IntPtr.Zero)
  311. throw new InvalidOperationException("Host already created");
  312. if (peerLimit < 0 || peerLimit > Library.maxPeers)
  313. throw new ArgumentOutOfRangeException("peerLimit");
  314. CheckChannelLimit(channelLimit);
  315. if (address != null) {
  316. var nativeAddress = address.Value.NativeData;
  317. nativeHost = Native.enet_host_create(ref nativeAddress, (IntPtr)peerLimit, (IntPtr)channelLimit, incomingBandwidth, outgoingBandwidth);
  318. } else {
  319. nativeHost = Native.enet_host_create(IntPtr.Zero, (IntPtr)peerLimit, (IntPtr)channelLimit, incomingBandwidth, outgoingBandwidth);
  320. }
  321. if (nativeHost == IntPtr.Zero)
  322. throw new ENetException(0, "Host creation call failed");
  323. }
  324. public void Broadcast(byte channelID, ref Packet packet) {
  325. CheckCreated();
  326. packet.CheckCreated();
  327. Native.enet_host_broadcast(nativeHost, channelID, packet.NativeData);
  328. packet.NativeData = IntPtr.Zero;
  329. }
  330. public int CheckEvents(out Event @event) {
  331. CheckCreated();
  332. ENetEvent nativeEvent;
  333. var result = Native.enet_host_check_events(nativeHost, out nativeEvent);
  334. if (result <= 0) {
  335. @event = new Event();
  336. return result;
  337. }
  338. @event = new Event(nativeEvent);
  339. return result;
  340. }
  341. public Peer Connect(Address address) {
  342. return Connect(address, 0, 0);
  343. }
  344. public Peer Connect(Address address, int channelLimit) {
  345. return Connect(address, channelLimit, 0);
  346. }
  347. public Peer Connect(Address address, int channelLimit, uint data) {
  348. CheckCreated();
  349. CheckChannelLimit(channelLimit);
  350. var nativeAddress = address.NativeData;
  351. var peer = new Peer(Native.enet_host_connect(nativeHost, ref nativeAddress, (IntPtr)channelLimit, data));
  352. if (peer.NativeData == IntPtr.Zero)
  353. throw new ENetException(0, "Host connect call failed");
  354. return peer;
  355. }
  356. public int Service(int timeout, out Event @event) {
  357. if (timeout < 0)
  358. throw new ArgumentOutOfRangeException("timeout");
  359. CheckCreated();
  360. ENetEvent nativeEvent;
  361. var result = Native.enet_host_service(nativeHost, out nativeEvent, (uint)timeout);
  362. if (result <= 0) {
  363. @event = new Event();
  364. return result;
  365. }
  366. @event = new Event(nativeEvent);
  367. return result;
  368. }
  369. public void SetBandwidthLimit(uint incomingBandwidth, uint outgoingBandwidth) {
  370. CheckCreated();
  371. Native.enet_host_bandwidth_limit(nativeHost, incomingBandwidth, outgoingBandwidth);
  372. }
  373. public void SetChannelLimit(int channelLimit) {
  374. CheckCreated();
  375. CheckChannelLimit(channelLimit);
  376. Native.enet_host_channel_limit(nativeHost, (IntPtr)channelLimit);
  377. }
  378. public void Flush() {
  379. CheckCreated();
  380. Native.enet_host_flush(nativeHost);
  381. }
  382. }
  383. public struct Peer {
  384. private IntPtr nativePeer;
  385. internal IntPtr NativeData {
  386. get {
  387. return nativePeer;
  388. }
  389. set {
  390. nativePeer = value;
  391. }
  392. }
  393. public Peer(IntPtr peer) {
  394. nativePeer = peer;
  395. }
  396. public bool IsSet {
  397. get {
  398. return nativePeer != IntPtr.Zero;
  399. }
  400. }
  401. public uint ID {
  402. get {
  403. return Native.enet_peer_get_id(nativePeer);
  404. }
  405. }
  406. public Address Address {
  407. get {
  408. return Native.enet_peer_get_address(nativePeer);
  409. }
  410. }
  411. public PeerState State {
  412. get {
  413. return nativePeer == IntPtr.Zero ? PeerState.Uninitialized : Native.enet_peer_get_state(nativePeer);
  414. }
  415. }
  416. public uint RoundTripTime {
  417. get {
  418. return Native.enet_peer_get_rtt(nativePeer);
  419. }
  420. }
  421. public ulong PacketsSent {
  422. get {
  423. return Native.enet_peer_get_packets_sent(nativePeer);
  424. }
  425. }
  426. public uint PacketsLost {
  427. get {
  428. return Native.enet_peer_get_packets_lost(nativePeer);
  429. }
  430. }
  431. public ulong BytesSent {
  432. get {
  433. return Native.enet_peer_get_bytes_sent(nativePeer);
  434. }
  435. }
  436. public ulong BytesReceived {
  437. get {
  438. return Native.enet_peer_get_bytes_received(nativePeer);
  439. }
  440. }
  441. public IntPtr Data {
  442. get {
  443. return Native.enet_peer_get_data(nativePeer);
  444. }
  445. set {
  446. Native.enet_peer_set_data(nativePeer, value);
  447. }
  448. }
  449. internal void CheckCreated() {
  450. if (nativePeer == IntPtr.Zero)
  451. throw new InvalidOperationException("Peer not created");
  452. }
  453. public void ConfigureThrottle(uint interval, uint acceleration, uint deceleration) {
  454. CheckCreated();
  455. Native.enet_peer_throttle_configure(nativePeer, interval, acceleration, deceleration);
  456. }
  457. public bool Send(byte channelID, ref Packet packet) {
  458. CheckCreated();
  459. return Native.enet_peer_send(nativePeer, channelID, packet.NativeData) >= 0;
  460. }
  461. public void Ping() {
  462. CheckCreated();
  463. Native.enet_peer_ping(nativePeer);
  464. }
  465. public void PingInterval(uint interval) {
  466. CheckCreated();
  467. Native.enet_peer_ping_interval(nativePeer, interval);
  468. }
  469. public void Disconnect(uint data) {
  470. CheckCreated();
  471. Native.enet_peer_disconnect(nativePeer, data);
  472. }
  473. public void DisconnectNow(uint data) {
  474. CheckCreated();
  475. Native.enet_peer_disconnect_now(nativePeer, data);
  476. }
  477. public void DisconnectLater(uint data) {
  478. CheckCreated();
  479. Native.enet_peer_disconnect_later(nativePeer, data);
  480. }
  481. public void Reset() {
  482. CheckCreated();
  483. Native.enet_peer_reset(nativePeer);
  484. }
  485. }
  486. public class ENetException : Exception {
  487. public ENetException(int code, string message) : base(message) {
  488. Code = code;
  489. }
  490. public int Code {
  491. get; private set;
  492. }
  493. }
  494. public static class Library {
  495. public const int maxChannelCount = 0xFF;
  496. public const int maxPeers = 0xFFF;
  497. public const int throttleScale = 32;
  498. public const int throttleAcceleration = 2;
  499. public const int throttleDeceleration = 2;
  500. public const int throttleInterval = 5000;
  501. public const uint version = (2 << 16) | (0 << 8) | (4);
  502. public static int Initialize() {
  503. return Native.enet_initialize();
  504. }
  505. public static void Deinitialize() {
  506. Native.enet_deinitialize();
  507. }
  508. public static uint Time {
  509. get {
  510. return Native.enet_time_get();
  511. }
  512. }
  513. }
  514. [SuppressUnmanagedCodeSecurity]
  515. internal static class Native {
  516. private const string nativeLibrary = "enet";
  517. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  518. internal static extern int enet_initialize();
  519. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  520. internal static extern void enet_deinitialize();
  521. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  522. internal static extern uint enet_time_get();
  523. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  524. internal static extern int enet_initialize_with_callbacks(uint version, ref ENetCallbacks inits);
  525. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  526. internal static extern int enet_address_get_host(ref ENetAddress address, byte[] hostName, IntPtr nameLength);
  527. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  528. internal static extern int enet_address_set_host(ref ENetAddress address, byte[] hostName);
  529. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  530. internal static extern int enet_address_get_host_ip(ref ENetAddress address, byte[] hostIP, IntPtr ipLength);
  531. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  532. internal static extern IntPtr enet_packet_create(byte[] data, IntPtr dataLength, PacketFlags flags);
  533. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  534. internal static extern IntPtr enet_packet_get_data(IntPtr packet);
  535. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  536. internal static extern int enet_packet_get_length(IntPtr packet);
  537. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  538. internal static extern void enet_packet_destroy(IntPtr packet);
  539. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  540. internal static extern IntPtr enet_host_create(IntPtr address, IntPtr peerLimit, IntPtr channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
  541. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  542. internal static extern IntPtr enet_host_create(ref ENetAddress address, IntPtr peerLimit, IntPtr channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
  543. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  544. internal static extern IntPtr enet_host_connect(IntPtr host, ref ENetAddress address, IntPtr channelCount, uint data);
  545. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  546. internal static extern void enet_host_broadcast(IntPtr host, byte channelID, IntPtr packet);
  547. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  548. internal static extern int enet_host_service(IntPtr host, IntPtr @event, uint timeout);
  549. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  550. internal static extern int enet_host_service(IntPtr host, out ENetEvent @event, uint timeout);
  551. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  552. internal static extern int enet_host_check_events(IntPtr host, out ENetEvent @event);
  553. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  554. internal static extern void enet_host_channel_limit(IntPtr host, IntPtr channelLimit);
  555. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  556. internal static extern void enet_host_bandwidth_limit(IntPtr host, uint incomingBandwidth, uint outgoingBandwidth);
  557. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  558. internal static extern uint enet_host_get_peers_count(IntPtr host);
  559. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  560. internal static extern uint enet_host_get_packets_sent(IntPtr host);
  561. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  562. internal static extern uint enet_host_get_packets_received(IntPtr host);
  563. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  564. internal static extern uint enet_host_get_bytes_sent(IntPtr host);
  565. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  566. internal static extern uint enet_host_get_bytes_received(IntPtr host);
  567. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  568. internal static extern void enet_host_flush(IntPtr host);
  569. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  570. internal static extern void enet_host_destroy(IntPtr host);
  571. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  572. internal static extern void enet_peer_throttle_configure(IntPtr peer, uint interval, uint acceleration, uint deceleration);
  573. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  574. internal static extern uint enet_peer_get_id(IntPtr peer);
  575. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  576. internal static extern Address enet_peer_get_address(IntPtr peer);
  577. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  578. internal static extern PeerState enet_peer_get_state(IntPtr peer);
  579. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  580. internal static extern uint enet_peer_get_rtt(IntPtr peer);
  581. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  582. internal static extern ulong enet_peer_get_packets_sent(IntPtr peer);
  583. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  584. internal static extern uint enet_peer_get_packets_lost(IntPtr peer);
  585. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  586. internal static extern ulong enet_peer_get_bytes_sent(IntPtr peer);
  587. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  588. internal static extern ulong enet_peer_get_bytes_received(IntPtr peer);
  589. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  590. internal static extern IntPtr enet_peer_get_data(IntPtr peer);
  591. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  592. internal static extern void enet_peer_set_data(IntPtr peer, IntPtr data);
  593. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  594. internal static extern int enet_peer_send(IntPtr peer, byte channelID, IntPtr packet);
  595. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  596. internal static extern void enet_peer_ping(IntPtr peer);
  597. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  598. internal static extern void enet_peer_ping_interval(IntPtr peer, uint pingInterval);
  599. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  600. internal static extern void enet_peer_disconnect(IntPtr peer, uint data);
  601. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  602. internal static extern void enet_peer_disconnect_now(IntPtr peer, uint data);
  603. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  604. internal static extern void enet_peer_disconnect_later(IntPtr peer, uint data);
  605. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  606. internal static extern void enet_peer_reset(IntPtr peer);
  607. }
  608. }