Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TeredoHelper.cs
Go to the documentation of this file.
1
using
System.ComponentModel
;
2
using
System.Net.Sockets
;
3
using
System.Runtime.InteropServices
;
4
using
System.Threading
;
5
6
namespace
System.Net.NetworkInformation
;
7
8
internal
sealed
class
TeredoHelper
9
{
10
private
readonly Action<object>
_callback
;
11
12
private
readonly
object
_state
;
13
14
private
bool
_runCallbackCalled
;
15
16
private
GCHandle
_gcHandle
;
17
18
private
SafeCancelMibChangeNotify
_cancelHandle
;
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
{
54
_cancelHandle
?.
Dispose
();
55
if
(
_gcHandle
.
IsAllocated
)
56
{
57
_gcHandle
.
Free
();
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
}
System.Net.NetworkInformation.SafeCancelMibChangeNotify
Definition
SafeCancelMibChangeNotify.cs:6
System.Net.NetworkInformation.SafeFreeMibTable
Definition
SafeFreeMibTable.cs:6
System.Net.NetworkInformation.TeredoHelper._runCallbackCalled
bool _runCallbackCalled
Definition
TeredoHelper.cs:14
System.Net.NetworkInformation.TeredoHelper._state
readonly object _state
Definition
TeredoHelper.cs:12
System.Net.NetworkInformation.TeredoHelper.TeredoHelper
TeredoHelper(Action< object > callback, object state)
Definition
TeredoHelper.cs:20
System.Net.NetworkInformation.TeredoHelper._cancelHandle
SafeCancelMibChangeNotify _cancelHandle
Definition
TeredoHelper.cs:18
System.Net.NetworkInformation.TeredoHelper._gcHandle
GCHandle _gcHandle
Definition
TeredoHelper.cs:16
System.Net.NetworkInformation.TeredoHelper.Dispose
void Dispose()
Definition
TeredoHelper.cs:52
System.Net.NetworkInformation.TeredoHelper.UnsafeNotifyStableUnicastIpAddressTable
static unsafe bool UnsafeNotifyStableUnicastIpAddressTable(Action< object > callback, object state)
Definition
TeredoHelper.cs:27
System.Net.NetworkInformation.TeredoHelper.OnStabilized
static void OnStabilized(IntPtr context, IntPtr table)
Definition
TeredoHelper.cs:62
System.Net.NetworkInformation.TeredoHelper._callback
readonly Action< object > _callback
Definition
TeredoHelper.cs:10
System.Net.NetworkInformation.TeredoHelper
Definition
TeredoHelper.cs:9
System.Runtime.InteropServices.SafeHandle.Dispose
void Dispose()
Definition
SafeHandle.cs:57
System.Threading.ThreadPool.QueueUserWorkItem
static bool QueueUserWorkItem(WaitCallback callBack)
Definition
ThreadPool.cs:498
System.Threading.ThreadPool
Definition
ThreadPool.cs:11
Win32Exception
System.ComponentModel
Definition
ColumnAttribute.cs:3
System.Net.NetworkInformation
Definition
DuplicateAddressDetectionState.cs:1
System.Net.Sockets.AddressFamily
AddressFamily
Definition
AddressFamily.cs:4
System.Net.Sockets
Definition
AddressInfoHints.cs:1
System.Runtime.InteropServices
Definition
SequenceMarshal.cs:4
System.Threading
Definition
TaskToApm.cs:3
System.ExceptionArgument.state
@ state
System.IntPtr
Definition
IntPtr.cs:14
System.Runtime.InteropServices.GCHandle.ToIntPtr
static IntPtr ToIntPtr(GCHandle value)
Definition
GCHandle.cs:138
System.Runtime.InteropServices.GCHandle.IsAllocated
bool IsAllocated
Definition
GCHandle.cs:32
System.Runtime.InteropServices.GCHandle.Free
void Free()
Definition
GCHandle.cs:91
System.Runtime.InteropServices.GCHandle.Alloc
static GCHandle Alloc(object? value)
Definition
GCHandle.cs:81
System.Runtime.InteropServices.GCHandle.FromIntPtr
static GCHandle FromIntPtr(IntPtr value)
Definition
GCHandle.cs:127
System.Runtime.InteropServices.GCHandle
Definition
GCHandle.cs:9
source
System.Net.NetworkInformation
System.Net.NetworkInformation
TeredoHelper.cs
Generated by
1.10.0