Table of Contents

Class TcpStreamConnection

Namespace
VpnHood.Core.Tunneling.Connections
Assembly
VpnHood.Core.Tunneling.dll

Represents a TCP connection as a stream connection.

public sealed class TcpStreamConnection : IStreamConnection, IDisposable, IAsyncDisposable
Inheritance
TcpStreamConnection
Implements
Inherited Members

Constructors

TcpStreamConnection(TcpClient, Stream, string, bool, string?)

Initializes a new instance of the TcpStreamConnection class, on a stream over the TCP client's.

public TcpStreamConnection(TcpClient tcpClient, Stream stream, string connectionName, bool isServer, string? connectionId = null)

Parameters

tcpClient TcpClient

The connected TCP client, which the connection owns.

stream Stream

The stream to read and write through, over the client's, which the connection owns.

connectionName string

The connection's name, which its logs carry.

isServer bool

true for the server's side of the connection.

connectionId string

The connection's ID, or null for a new one.

Exceptions

ObjectDisposedException

The TCP client has no socket: it is closed.

InvalidOperationException

The TCP client's socket has no local or remote endpoint.

TcpStreamConnection(TcpClient, string, bool, string?)

Initializes a new instance of the TcpStreamConnection class, on the TCP client's own stream.

public TcpStreamConnection(TcpClient tcpClient, string connectionName, bool isServer, string? connectionId = null)

Parameters

tcpClient TcpClient

The connected TCP client, which the connection owns.

connectionName string

The connection's name, which its logs carry.

isServer bool

true for the server's side of the connection.

connectionId string

The connection's ID, or null for a new one.

Exceptions

ObjectDisposedException

The TCP client has no socket: it is closed.

InvalidOperationException

The TCP client's socket has no local or remote endpoint.

Properties

Connected

Gets a value indicating whether the connection is up.

public bool Connected { get; }

Property Value

bool

Remarks

It asks the TCP client's socket.

ConnectionId

Gets or sets the connection's ID, which its logs carry.

public string ConnectionId { get; set; }

Property Value

string

ConnectionName

Gets the connection's name, which its logs carry.

public string ConnectionName { get; }

Property Value

string

IsServer

Gets a value indicating whether this is the server's side of the connection, which its logs show.

public bool IsServer { get; }

Property Value

bool

LocalEndPoint

Gets the connection's local endpoint.

public IPEndPoint LocalEndPoint { get; }

Property Value

IPEndPoint

RemoteEndPoint

Gets the peer's endpoint.

public IPEndPoint RemoteEndPoint { get; }

Property Value

IPEndPoint

RequireHttpResponse

Gets or sets a value indicating whether an HTTP response to the connection's request header is still due before the request's own answer: the server writes it, and the client reads it.

public bool RequireHttpResponse { get; set; }

Property Value

bool

Stream

Gets the stream the connection carries.

public Stream Stream { get; }

Property Value

Stream

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Remarks

It closes the stream and the TCP client at once.

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

Remarks

It closes the stream gracefully, then the TCP client, which a failure of the stream's close skips; a second call waits for the first one's end.

DrainArrived(CancellationToken)

Reads off what has arrived, before a close: up to 1 MB, for up to a tenth of a second, until the connection is quiet for 10 milliseconds or its peer has closed it.

public Task DrainArrived(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task

A task that completes once the drain ends.

Remarks

A close with unread data can discard a reply already written, so it reads what has arrived, as a web server's input pipe does, bounded in bytes and time so a sender cannot prolong the close.

Exceptions

OperationCanceledException

cancellationToken was canceled.

PreventReuse()

Makes the connection's release close it rather than keep it for another request.

public void PreventReuse()

Remarks

A decorator passes it on, so it reaches the reusable connection however that is wrapped.

Reset()

Closes the connection with a reset rather than a FIN, as a server does that gives up on its peer.

public void Reset()

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

Remarks

It is the ID, the name and the side: id:name:server or id:name:client.