Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MockListener.cs
Go to the documentation of this file.
5
7
8internal sealed class MockListener : QuicListenerProvider
9{
10 private bool _disposed;
11
12 private readonly QuicListenerOptions _options;
13
14 private readonly IPEndPoint _listenEndPoint;
15
17
18 private static int s_mockPort;
19
21
23
25 {
26 if (options.ListenEndPoint == null || options.ListenEndPoint.Address != IPAddress.Loopback || options.ListenEndPoint.Port != 0)
27 {
28 throw new ArgumentException("Must pass loopback address and port 0");
29 }
31 int num = Interlocked.Increment(ref s_mockPort);
33 bool flag = s_listenerMap.TryAdd(num, this);
35 }
36
37 internal static MockListener TryGetListener(IPEndPoint endpoint)
38 {
39 if (endpoint.Address != IPAddress.Loopback || endpoint.Port == 0)
40 {
41 return null;
42 }
43 if (!s_listenerMap.TryGetValue(endpoint.Port, out var value))
44 {
45 return null;
46 }
47 return value;
48 }
49
51 {
53 MockConnection.ConnectionState state = await _listenQueue.Reader.ReadAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
55 }
56
62
63 private void CheckDisposed()
64 {
65 if (_disposed)
66 {
67 throw new ObjectDisposedException("QuicListener");
68 }
69 }
70
71 private void Dispose(bool disposing)
72 {
73 if (!_disposed)
74 {
75 if (disposing)
76 {
78 bool flag = s_listenerMap.TryRemove(_listenEndPoint.Port, out value);
79 }
80 _disposed = true;
81 }
82 }
83
85 {
86 Dispose(disposing: false);
87 }
88
89 public override void Dispose()
90 {
91 Dispose(disposing: true);
92 GC.SuppressFinalize(this);
93 }
94}
static void SuppressFinalize(object obj)
Definition GC.cs:202
Definition GC.cs:8
static readonly IPAddress Loopback
Definition IPAddress.cs:21
bool TryConnect(MockConnection.ConnectionState state)
override async ValueTask< QuicConnectionProvider > AcceptConnectionAsync(CancellationToken cancellationToken=default(CancellationToken))
Channel< MockConnection.ConnectionState > _listenQueue
static ConcurrentDictionary< int, MockListener > s_listenerMap
static MockListener TryGetListener(IPEndPoint endpoint)
static int Increment(ref int location)