Browse Source

Add runtime version check

nxrighthere 5 years ago
parent
commit
2fb3ae128a
2 changed files with 13 additions and 4 deletions
  1. 11 2
      Source/Managed/ENet.cs
  2. 2 2
      Source/Native/enet.h

+ 11 - 2
Source/Managed/ENet.cs

@@ -907,9 +907,12 @@ 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) | (3 << 8) | (9);
+		public const uint version = (2 << 16) | (4 << 8) | (0);
 
 
 		public static bool Initialize() {
 		public static bool Initialize() {
+			if (Native.enet_linked_version() != version)
+				throw new InvalidOperationException("Incompatatible version");
+
 			return Native.enet_initialize() == 0;
 			return Native.enet_initialize() == 0;
 		}
 		}
 
 
@@ -917,6 +920,9 @@ namespace ENet {
 			if (callbacks == null)
 			if (callbacks == null)
 				throw new ArgumentNullException("callbacks");
 				throw new ArgumentNullException("callbacks");
 
 
+			if (Native.enet_linked_version() != version)
+				throw new InvalidOperationException("Incompatatible version");
+
 			ENetCallbacks nativeCallbacks = callbacks.NativeData;
 			ENetCallbacks nativeCallbacks = callbacks.NativeData;
 
 
 			return Native.enet_initialize_with_callbacks(version, ref nativeCallbacks) == 0;
 			return Native.enet_initialize_with_callbacks(version, ref nativeCallbacks) == 0;
@@ -950,6 +956,9 @@ namespace ENet {
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_deinitialize();
 		internal static extern void enet_deinitialize();
 
 
+		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
+		internal static extern uint enet_linked_version();
+
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern uint enet_time_get();
 		internal static extern uint enet_time_get();
 
 
@@ -1130,4 +1139,4 @@ namespace ENet {
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		[DllImport(nativeLibrary, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_peer_reset(IntPtr peer);
 		internal static extern void enet_peer_reset(IntPtr peer);
 	}
 	}
-}
+}

+ 2 - 2
Source/Native/enet.h

@@ -30,8 +30,8 @@
 #include <time.h>
 #include <time.h>
 
 
 #define ENET_VERSION_MAJOR 2
 #define ENET_VERSION_MAJOR 2
-#define ENET_VERSION_MINOR 3
-#define ENET_VERSION_PATCH 9
+#define ENET_VERSION_MINOR 4
+#define ENET_VERSION_PATCH 0
 #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)