Browse Source

Add function for checking packet references

NX 7 years ago
parent
commit
4735518c58
2 changed files with 17 additions and 3 deletions
  1. 10 1
      Source/Managed/ENet.cs
  2. 7 2
      Source/Native/enet.h

+ 10 - 1
Source/Managed/ENet.cs

@@ -305,6 +305,12 @@ namespace ENet {
 			nativePacket = Native.enet_packet_create(data, (IntPtr)length, flags);
 			nativePacket = Native.enet_packet_create(data, (IntPtr)length, flags);
 		}
 		}
 
 
+		public bool CheckReferences() {
+			CheckCreated();
+
+			return Native.enet_packet_check_references(nativePacket) != 0;
+		}
+
 		public void CopyTo(byte[] destination) {
 		public void CopyTo(byte[] destination) {
 			if (destination == null)
 			if (destination == null)
 				throw new ArgumentNullException("destination");
 				throw new ArgumentNullException("destination");
@@ -787,7 +793,7 @@ namespace ENet {
 		public const uint timeoutLimit = 32;
 		public const uint timeoutLimit = 32;
 		public const uint timeoutMinimum = 5000;
 		public const uint timeoutMinimum = 5000;
 		public const uint timeoutMaximum = 30000;
 		public const uint timeoutMaximum = 30000;
-		public const uint version = (2 << 16) | (1 << 8) | (4);
+		public const uint version = (2 << 16) | (1 << 8) | (5);
 
 
 		public static bool Initialize() {
 		public static bool Initialize() {
 			return Native.enet_initialize() == 0;
 			return Native.enet_initialize() == 0;
@@ -839,6 +845,9 @@ namespace ENet {
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern IntPtr enet_packet_create(IntPtr data, IntPtr dataLength, PacketFlags flags);
 		internal static extern IntPtr enet_packet_create(IntPtr data, IntPtr dataLength, PacketFlags flags);
 
 
+		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
+		internal static extern int enet_packet_check_references(IntPtr packet);
+
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern IntPtr enet_packet_get_data(IntPtr packet);
 		internal static extern IntPtr enet_packet_get_data(IntPtr packet);
 
 

+ 7 - 2
Source/Native/enet.h

@@ -35,7 +35,7 @@
 
 
 #define ENET_VERSION_MAJOR 2
 #define ENET_VERSION_MAJOR 2
 #define ENET_VERSION_MINOR 1
 #define ENET_VERSION_MINOR 1
-#define ENET_VERSION_PATCH 4
+#define ENET_VERSION_PATCH 5
 #define ENET_VERSION_CREATE(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch))
 #define ENET_VERSION_CREATE(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch))
 #define ENET_VERSION_GET_MAJOR(version) (((version) >> 16) & 0xFF)
 #define ENET_VERSION_GET_MAJOR(version) (((version) >> 16) & 0xFF)
 #define ENET_VERSION_GET_MINOR(version) (((version) >> 8) & 0xFF)
 #define ENET_VERSION_GET_MINOR(version) (((version) >> 8) & 0xFF)
@@ -779,6 +779,7 @@ extern "C" {
     ENET_API void *              enet_packet_get_data(ENetPacket *);
     ENET_API void *              enet_packet_get_data(ENetPacket *);
     ENET_API int                 enet_packet_get_length(ENetPacket *);
     ENET_API int                 enet_packet_get_length(ENetPacket *);
     ENET_API void                enet_packet_set_free_callback(ENetPacket *, const void *);
     ENET_API void                enet_packet_set_free_callback(ENetPacket *, const void *);
+    ENET_API int                 enet_packet_check_references(ENetPacket *);
     ENET_API void                enet_packet_dispose(ENetPacket *);
     ENET_API void                enet_packet_dispose(ENetPacket *);
 
 
     ENET_API enet_uint32         enet_host_get_peers_count(ENetHost *);
     ENET_API enet_uint32         enet_host_get_peers_count(ENetHost *);
@@ -4551,6 +4552,10 @@ extern "C" {
         packet->freeCallback = (ENetPacketFreeCallback)callback;
         packet->freeCallback = (ENetPacketFreeCallback)callback;
     }
     }
 
 
+    int enet_packet_check_references(ENetPacket *packet) {
+        return (int)packet->referenceCount;
+    }
+
     void enet_packet_dispose(ENetPacket *packet) {
     void enet_packet_dispose(ENetPacket *packet) {
         if (packet->referenceCount == 0) {
         if (packet->referenceCount == 0) {
             enet_packet_destroy(packet);
             enet_packet_destroy(packet);
@@ -5617,4 +5622,4 @@ extern "C" {
 }
 }
 #endif
 #endif
 #endif
 #endif
-#endif
+#endif