Class LocalTcpListener
- Namespace
- VpnHood.Net.TcpStack
- Assembly
- VpnHood.Net.TcpStack.dll
Provides a listener of a LocalTcpStack: it queues the connections that complete their handshake until they are accepted, the way TcpListener does for sockets.
public sealed class LocalTcpListener : ITcpListener, IDisposable
- Inheritance
-
LocalTcpListener
- Implements
- Inherited Members
Remarks
A full queue (AcceptQueueCapacity) closes a new connection instead.
Properties
IsAny
Gets a value indicating whether this is the listener of ListenAny().
public bool IsAny { get; }
Property Value
LocalEndPoint
Gets the endpoint this listener takes connections to, or null for the listener of ListenAny(), which takes the connections no endpoint listener takes.
public IpEndPointValue? LocalEndPoint { get; }
Property Value
Methods
AcceptAllAsync(CancellationToken)
Accepts connections as they complete their handshake, until the listener is stopped.
public IAsyncEnumerable<LocalTcpClient> AcceptAllAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- IAsyncEnumerable<LocalTcpClient>
The accepted connections; the caller owns each and disposes it.
Exceptions
- OperationCanceledException
cancellationTokenwas canceled.
AcceptAsync(CancellationToken)
Accepts the next connection that completes its handshake.
public ValueTask<LocalTcpClient> AcceptAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- ValueTask<LocalTcpClient>
A task whose result is the accepted connection, which the caller owns and disposes.
Exceptions
- OperationCanceledException
cancellationTokenwas canceled.- ChannelClosedException
The listener is stopped.
Dispose()
Stops the listener, as Stop() does.
public void Dispose()
Stop()
Stops the listener: ends its accepts, closes the connections in its queue, and leaves the stack, so a new listener can take its endpoint. A handshake under way for it is closed when it completes; connections already accepted stay open. Calling it again does nothing.
public void Stop()