Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TeredoHelper.cs
Go to the documentation of this file.
5
7
8internal sealed class TeredoHelper
9{
10 private readonly Action<object> _callback;
11
12 private readonly object _state;
13
14 private bool _runCallbackCalled;
15
17
19
20 private TeredoHelper(Action<object> callback, object state)
21 {
22 _callback = callback;
23 _state = state;
24 _gcHandle = GCHandle.Alloc(this);
25 }
26
27 public unsafe static bool UnsafeNotifyStableUnicastIpAddressTable(Action<object> callback, object state)
28 {
29 TeredoHelper teredoHelper = new TeredoHelper(callback, state);
30 try
31 {
32 SafeFreeMibTable table;
33 uint num = global::Interop.IpHlpApi.NotifyStableUnicastIpAddressTable(AddressFamily.Unspecified, out table, (delegate* unmanaged<IntPtr, IntPtr, void>)(delegate*<IntPtr, IntPtr, void>)(&OnStabilized), GCHandle.ToIntPtr(teredoHelper._gcHandle), out teredoHelper._cancelHandle);
34 table.Dispose();
35 switch (num)
36 {
37 case 997u:
38 teredoHelper = null;
39 return false;
40 default:
41 throw new Win32Exception((int)num);
42 case 0u:
43 return true;
44 }
45 }
46 finally
47 {
48 teredoHelper?.Dispose();
49 }
50 }
51
52 private void Dispose()
53 {
56 {
58 }
59 }
60
61 [UnmanagedCallersOnly]
62 private static void OnStabilized(IntPtr context, IntPtr table)
63 {
64 global::Interop.IpHlpApi.FreeMibTable(table);
65 TeredoHelper teredoHelper = (TeredoHelper)GCHandle.FromIntPtr(context).Target;
66 if (teredoHelper._runCallbackCalled)
67 {
68 return;
69 }
70 lock (teredoHelper)
71 {
72 if (!teredoHelper._runCallbackCalled)
73 {
74 teredoHelper._runCallbackCalled = true;
75 ThreadPool.QueueUserWorkItem(delegate(object o)
76 {
77 TeredoHelper teredoHelper2 = (TeredoHelper)o;
78 teredoHelper2.Dispose();
79 teredoHelper2._callback(teredoHelper2._state);
80 }, teredoHelper);
81 }
82 }
83 }
84}
TeredoHelper(Action< object > callback, object state)
SafeCancelMibChangeNotify _cancelHandle
static unsafe bool UnsafeNotifyStableUnicastIpAddressTable(Action< object > callback, object state)
static void OnStabilized(IntPtr context, IntPtr table)
static bool QueueUserWorkItem(WaitCallback callBack)
static IntPtr ToIntPtr(GCHandle value)
Definition GCHandle.cs:138
static GCHandle Alloc(object? value)
Definition GCHandle.cs:81
static GCHandle FromIntPtr(IntPtr value)
Definition GCHandle.cs:127