ENet.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  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 ushort Port {
  93. get {
  94. return nativeAddress.port;
  95. }
  96. set {
  97. nativeAddress.port = value;
  98. }
  99. }
  100. public bool SetHost(string hostName) {
  101. if (hostName == null)
  102. throw new ArgumentNullException("hostName");
  103. return Native.enet_address_set_host(ref nativeAddress, Encoding.ASCII.GetBytes(hostName)) == 0;
  104. }
  105. public string GetIP() {
  106. byte[] data = new byte[256];
  107. if (Native.enet_address_get_host_ip(ref nativeAddress, data, (IntPtr)256) == 0)
  108. return Encoding.ASCII.GetString(data);
  109. else
  110. return String.Empty;
  111. }
  112. public string GetName() {
  113. byte[] data = new byte[256];
  114. if (Native.enet_address_get_host(ref nativeAddress, data, (IntPtr)256) == 0)
  115. return Encoding.ASCII.GetString(data);
  116. else
  117. return String.Empty;
  118. }
  119. }
  120. public struct Event {
  121. private ENetEvent nativeEvent;
  122. internal ENetEvent NativeData {
  123. get {
  124. return nativeEvent;
  125. }
  126. set {
  127. nativeEvent = value;
  128. }
  129. }
  130. public Event(ENetEvent @event) {
  131. nativeEvent = @event;
  132. }
  133. public EventType Type {
  134. get {
  135. return nativeEvent.type;
  136. }
  137. }
  138. public Peer Peer {
  139. get {
  140. return new Peer(nativeEvent.peer);
  141. }
  142. }
  143. public byte ChannelID {
  144. get {
  145. return nativeEvent.channelID;
  146. }
  147. }
  148. public uint Data {
  149. get {
  150. return nativeEvent.data;
  151. }
  152. }
  153. public Packet Packet {
  154. get {
  155. return new Packet(nativeEvent.packet);
  156. }
  157. }
  158. }
  159. public struct Packet : IDisposable {
  160. private IntPtr nativePacket;
  161. internal IntPtr NativeData {
  162. get {
  163. return nativePacket;
  164. }
  165. set {
  166. nativePacket = value;
  167. }
  168. }
  169. public Packet(IntPtr packet) {
  170. nativePacket = packet;
  171. }
  172. public void Dispose() {
  173. if (nativePacket != IntPtr.Zero) {
  174. Native.enet_packet_destroy(nativePacket);
  175. nativePacket = IntPtr.Zero;
  176. }
  177. }
  178. public bool IsSet {
  179. get {
  180. return nativePacket != IntPtr.Zero;
  181. }
  182. }
  183. public IntPtr Data {
  184. get {
  185. CheckCreated();
  186. return Native.enet_packet_get_data(nativePacket);
  187. }
  188. }
  189. public int Length {
  190. get {
  191. CheckCreated();
  192. return Native.enet_packet_get_length(nativePacket);
  193. }
  194. }
  195. internal void CheckCreated() {
  196. if (nativePacket == IntPtr.Zero)
  197. throw new InvalidOperationException("Packet not created");
  198. }
  199. public void Create(byte[] data) {
  200. if (data == null)
  201. throw new ArgumentNullException("data");
  202. Create(data, data.Length);
  203. }
  204. public void Create(byte[] data, int length) {
  205. Create(data, length, PacketFlags.None);
  206. }
  207. public void Create(byte[] data, int length, PacketFlags flags) {
  208. if (data == null)
  209. throw new ArgumentNullException("data");
  210. if (length < 0 || length > data.Length)
  211. throw new ArgumentOutOfRangeException();
  212. nativePacket = Native.enet_packet_create(data, (IntPtr)length, flags);
  213. }
  214. public void CopyTo(byte[] array) {
  215. if (array == null)
  216. throw new ArgumentNullException("array");
  217. CopyTo(array, 0, array.Length);
  218. }
  219. public void CopyTo(byte[] array, int offset, int length) {
  220. if (array == null)
  221. throw new ArgumentNullException("array");
  222. if (offset < 0 || length < 0 || length > array.Length - offset)
  223. throw new ArgumentOutOfRangeException();
  224. CheckCreated();
  225. if (length > Length - offset)
  226. throw new ArgumentOutOfRangeException();
  227. if (length > 0)
  228. Marshal.Copy((IntPtr)((Int64)Data + offset), array, offset, length);
  229. }
  230. }
  231. public class Host : IDisposable {
  232. private IntPtr nativeHost;
  233. internal IntPtr NativeData {
  234. get {
  235. return nativeHost;
  236. }
  237. set {
  238. nativeHost = value;
  239. }
  240. }
  241. public void Dispose() {
  242. Dispose(true);
  243. }
  244. protected virtual void Dispose(bool disposing) {
  245. try {
  246. if (nativeHost != IntPtr.Zero) {
  247. Native.enet_host_destroy(nativeHost);
  248. nativeHost = IntPtr.Zero;
  249. }
  250. }
  251. catch { }
  252. }
  253. ~Host() {
  254. Dispose(false);
  255. }
  256. public bool IsSet {
  257. get {
  258. return nativeHost != IntPtr.Zero;
  259. }
  260. }
  261. public uint PeersCount {
  262. get {
  263. return Native.enet_host_get_peers_count(nativeHost);
  264. }
  265. }
  266. public uint PacketsSent {
  267. get {
  268. return Native.enet_host_get_packets_sent(nativeHost);
  269. }
  270. }
  271. public uint PacketsReceived {
  272. get {
  273. return Native.enet_host_get_packets_received(nativeHost);
  274. }
  275. }
  276. public uint BytesSent {
  277. get {
  278. return Native.enet_host_get_bytes_sent(nativeHost);
  279. }
  280. }
  281. public uint BytesReceived {
  282. get {
  283. return Native.enet_host_get_bytes_received(nativeHost);
  284. }
  285. }
  286. internal void CheckCreated() {
  287. if (nativeHost == IntPtr.Zero)
  288. throw new InvalidOperationException("Host not created");
  289. }
  290. private void CheckChannelLimit(int channelLimit) {
  291. if (channelLimit < 0 || channelLimit > Library.maxChannelCount)
  292. throw new ArgumentOutOfRangeException("channelLimit");
  293. }
  294. public void Create() {
  295. Create(null, 1, 0);
  296. }
  297. public void Create(Address? address, int peerLimit) {
  298. Create(address, peerLimit, 0);
  299. }
  300. public void Create(Address? address, int peerLimit, int channelLimit) {
  301. Create(address, peerLimit, channelLimit, 0, 0);
  302. }
  303. public void Create(int peerLimit, int channelLimit, uint incomingBandwidth, uint outgoingBandwidth) {
  304. Create(null, peerLimit, channelLimit, incomingBandwidth, outgoingBandwidth);
  305. }
  306. public void Create(Address? address, int peerLimit, int channelLimit, uint incomingBandwidth, uint outgoingBandwidth) {
  307. if (nativeHost != IntPtr.Zero)
  308. throw new InvalidOperationException("Host already created");
  309. if (peerLimit < 0 || peerLimit > Library.maxPeers)
  310. throw new ArgumentOutOfRangeException("peerLimit");
  311. CheckChannelLimit(channelLimit);
  312. if (address != null) {
  313. var nativeAddress = address.Value.NativeData;
  314. nativeHost = Native.enet_host_create(ref nativeAddress, (IntPtr)peerLimit, (IntPtr)channelLimit, incomingBandwidth, outgoingBandwidth);
  315. } else {
  316. nativeHost = Native.enet_host_create(IntPtr.Zero, (IntPtr)peerLimit, (IntPtr)channelLimit, incomingBandwidth, outgoingBandwidth);
  317. }
  318. if (nativeHost == IntPtr.Zero)
  319. throw new ENetException(0, "Host creation call failed");
  320. }
  321. public void Broadcast(byte channelID, ref Packet packet) {
  322. CheckCreated();
  323. packet.CheckCreated();
  324. Native.enet_host_broadcast(nativeHost, channelID, packet.NativeData);
  325. packet.NativeData = IntPtr.Zero;
  326. }
  327. public int CheckEvents(out Event @event) {
  328. CheckCreated();
  329. ENetEvent nativeEvent;
  330. var result = Native.enet_host_check_events(nativeHost, out nativeEvent);
  331. if (result <= 0) {
  332. @event = new Event();
  333. return result;
  334. }
  335. @event = new Event(nativeEvent);
  336. return result;
  337. }
  338. public Peer Connect(Address address) {
  339. return Connect(address, 0, 0);
  340. }
  341. public Peer Connect(Address address, int channelLimit) {
  342. return Connect(address, channelLimit, 0);
  343. }
  344. public Peer Connect(Address address, int channelLimit, uint data) {
  345. CheckCreated();
  346. CheckChannelLimit(channelLimit);
  347. var nativeAddress = address.NativeData;
  348. var peer = new Peer(Native.enet_host_connect(nativeHost, ref nativeAddress, (IntPtr)channelLimit, data));
  349. if (peer.NativeData == IntPtr.Zero)
  350. throw new ENetException(0, "Host connect call failed");
  351. return peer;
  352. }
  353. public int Service(int timeout, out Event @event) {
  354. if (timeout < 0)
  355. throw new ArgumentOutOfRangeException("timeout");
  356. CheckCreated();
  357. ENetEvent nativeEvent;
  358. var result = Native.enet_host_service(nativeHost, out nativeEvent, (uint)timeout);
  359. if (result <= 0) {
  360. @event = new Event();
  361. return result;
  362. }
  363. @event = new Event(nativeEvent);
  364. return result;
  365. }
  366. public void SetBandwidthLimit(uint incomingBandwidth, uint outgoingBandwidth) {
  367. CheckCreated();
  368. Native.enet_host_bandwidth_limit(nativeHost, incomingBandwidth, outgoingBandwidth);
  369. }
  370. public void SetChannelLimit(int channelLimit) {
  371. CheckCreated();
  372. CheckChannelLimit(channelLimit);
  373. Native.enet_host_channel_limit(nativeHost, (IntPtr)channelLimit);
  374. }
  375. public void Flush() {
  376. CheckCreated();
  377. Native.enet_host_flush(nativeHost);
  378. }
  379. }
  380. public struct Peer {
  381. private IntPtr nativePeer;
  382. internal IntPtr NativeData {
  383. get {
  384. return nativePeer;
  385. }
  386. set {
  387. nativePeer = value;
  388. }
  389. }
  390. public Peer(IntPtr peer) {
  391. nativePeer = peer;
  392. }
  393. public bool IsSet {
  394. get {
  395. return nativePeer != IntPtr.Zero;
  396. }
  397. }
  398. public uint ID {
  399. get {
  400. return Native.enet_peer_get_id(nativePeer);
  401. }
  402. }
  403. public Address Address {
  404. get {
  405. return Native.enet_peer_get_address(nativePeer);
  406. }
  407. }
  408. public PeerState State {
  409. get {
  410. return nativePeer == IntPtr.Zero ? PeerState.Uninitialized : Native.enet_peer_get_state(nativePeer);
  411. }
  412. }
  413. public uint RoundTripTime {
  414. get {
  415. return Native.enet_peer_get_rtt(nativePeer);
  416. }
  417. }
  418. public ulong PacketsSent {
  419. get {
  420. return Native.enet_peer_get_packets_sent(nativePeer);
  421. }
  422. }
  423. public uint PacketsLost {
  424. get {
  425. return Native.enet_peer_get_packets_lost(nativePeer);
  426. }
  427. }
  428. public ulong BytesSent {
  429. get {
  430. return Native.enet_peer_get_bytes_sent(nativePeer);
  431. }
  432. }
  433. public ulong BytesReceived {
  434. get {
  435. return Native.enet_peer_get_bytes_received(nativePeer);
  436. }
  437. }
  438. public IntPtr Data {
  439. get {
  440. return Native.enet_peer_get_data(nativePeer);
  441. }
  442. set {
  443. Native.enet_peer_set_data(nativePeer, value);
  444. }
  445. }
  446. internal void CheckCreated() {
  447. if (nativePeer == IntPtr.Zero)
  448. throw new InvalidOperationException("Peer not created");
  449. }
  450. public void ConfigureThrottle(uint interval, uint acceleration, uint deceleration) {
  451. CheckCreated();
  452. Native.enet_peer_throttle_configure(nativePeer, interval, acceleration, deceleration);
  453. }
  454. public bool Send(byte channelID, Packet packet) {
  455. CheckCreated();
  456. return Native.enet_peer_send(nativePeer, channelID, packet.NativeData) >= 0;
  457. }
  458. public void Ping() {
  459. CheckCreated();
  460. Native.enet_peer_ping(nativePeer);
  461. }
  462. public void PingInterval(uint interval) {
  463. CheckCreated();
  464. Native.enet_peer_ping_interval(nativePeer, interval);
  465. }
  466. public void Disconnect(uint data) {
  467. CheckCreated();
  468. Native.enet_peer_disconnect(nativePeer, data);
  469. }
  470. public void DisconnectNow(uint data) {
  471. CheckCreated();
  472. Native.enet_peer_disconnect_now(nativePeer, data);
  473. }
  474. public void DisconnectLater(uint data) {
  475. CheckCreated();
  476. Native.enet_peer_disconnect_later(nativePeer, data);
  477. }
  478. public void Reset() {
  479. CheckCreated();
  480. Native.enet_peer_reset(nativePeer);
  481. }
  482. }
  483. public class ENetException : Exception {
  484. public ENetException(int code, string message) : base(message) {
  485. Code = code;
  486. }
  487. public int Code {
  488. get; private set;
  489. }
  490. }
  491. public static class Library {
  492. public const int maxChannelCount = 0xFF;
  493. public const int maxPeers = 0xFFF;
  494. public const int throttleScale = 32;
  495. public const int throttleAcceleration = 2;
  496. public const int throttleDeceleration = 2;
  497. public const int throttleInterval = 5000;
  498. public const uint version = (2 << 16) | (0 << 8) | (4);
  499. public static int Initialize() {
  500. return Native.enet_initialize();
  501. }
  502. public static void Deinitialize() {
  503. Native.enet_deinitialize();
  504. }
  505. public static uint Time {
  506. get {
  507. return Native.enet_time_get();
  508. }
  509. }
  510. }
  511. [SuppressUnmanagedCodeSecurity]
  512. internal static class Native {
  513. private const string nativeLibrary = "enet";
  514. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  515. internal static extern int enet_initialize();
  516. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  517. internal static extern void enet_deinitialize();
  518. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  519. internal static extern uint enet_time_get();
  520. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  521. internal static extern int enet_initialize_with_callbacks(uint version, ref ENetCallbacks inits);
  522. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  523. internal static extern int enet_address_get_host(ref ENetAddress address, byte[] hostName, IntPtr nameLength);
  524. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  525. internal static extern int enet_address_set_host(ref ENetAddress address, byte[] hostName);
  526. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  527. internal static extern int enet_address_get_host_ip(ref ENetAddress address, byte[] hostIP, IntPtr ipLength);
  528. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  529. internal static extern IntPtr enet_packet_create(byte[] data, IntPtr dataLength, PacketFlags flags);
  530. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  531. internal static extern IntPtr enet_packet_get_data(IntPtr packet);
  532. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  533. internal static extern int enet_packet_get_length(IntPtr packet);
  534. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  535. internal static extern void enet_packet_destroy(IntPtr packet);
  536. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  537. internal static extern IntPtr enet_host_create(IntPtr address, IntPtr peerLimit, IntPtr channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
  538. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  539. internal static extern IntPtr enet_host_create(ref ENetAddress address, IntPtr peerLimit, IntPtr channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
  540. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  541. internal static extern IntPtr enet_host_connect(IntPtr host, ref ENetAddress address, IntPtr channelCount, uint data);
  542. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  543. internal static extern void enet_host_broadcast(IntPtr host, byte channelID, IntPtr packet);
  544. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  545. internal static extern int enet_host_service(IntPtr host, IntPtr @event, uint timeout);
  546. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  547. internal static extern int enet_host_service(IntPtr host, out ENetEvent @event, uint timeout);
  548. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  549. internal static extern int enet_host_check_events(IntPtr host, out ENetEvent @event);
  550. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  551. internal static extern void enet_host_channel_limit(IntPtr host, IntPtr channelLimit);
  552. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  553. internal static extern void enet_host_bandwidth_limit(IntPtr host, uint incomingBandwidth, uint outgoingBandwidth);
  554. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  555. internal static extern uint enet_host_get_peers_count(IntPtr host);
  556. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  557. internal static extern uint enet_host_get_packets_sent(IntPtr host);
  558. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  559. internal static extern uint enet_host_get_packets_received(IntPtr host);
  560. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  561. internal static extern uint enet_host_get_bytes_sent(IntPtr host);
  562. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  563. internal static extern uint enet_host_get_bytes_received(IntPtr host);
  564. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  565. internal static extern void enet_host_flush(IntPtr host);
  566. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  567. internal static extern void enet_host_destroy(IntPtr host);
  568. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  569. internal static extern void enet_peer_throttle_configure(IntPtr peer, uint interval, uint acceleration, uint deceleration);
  570. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  571. internal static extern uint enet_peer_get_id(IntPtr peer);
  572. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  573. internal static extern Address enet_peer_get_address(IntPtr peer);
  574. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  575. internal static extern PeerState enet_peer_get_state(IntPtr peer);
  576. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  577. internal static extern uint enet_peer_get_rtt(IntPtr peer);
  578. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  579. internal static extern ulong enet_peer_get_packets_sent(IntPtr peer);
  580. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  581. internal static extern uint enet_peer_get_packets_lost(IntPtr peer);
  582. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  583. internal static extern ulong enet_peer_get_bytes_sent(IntPtr peer);
  584. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  585. internal static extern ulong enet_peer_get_bytes_received(IntPtr peer);
  586. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  587. internal static extern IntPtr enet_peer_get_data(IntPtr peer);
  588. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  589. internal static extern void enet_peer_set_data(IntPtr peer, IntPtr data);
  590. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  591. internal static extern int enet_peer_send(IntPtr peer, byte channelID, IntPtr packet);
  592. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  593. internal static extern void enet_peer_ping(IntPtr peer);
  594. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  595. internal static extern void enet_peer_ping_interval(IntPtr peer, uint pingInterval);
  596. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  597. internal static extern void enet_peer_disconnect(IntPtr peer, uint data);
  598. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  599. internal static extern void enet_peer_disconnect_now(IntPtr peer, uint data);
  600. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  601. internal static extern void enet_peer_disconnect_later(IntPtr peer, uint data);
  602. [DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
  603. internal static extern void enet_peer_reset(IntPtr peer);
  604. }
  605. }