Class StreamForwardingChannel
Represents a channel that forwards one TCP connection: it passes the bytes both ways between the connection and a tunnel connection, within the session's speed limits.
public class StreamForwardingChannel : IStreamForwardingChannel, IChannel, IDisposable, IAsyncDisposable
- Inheritance
-
StreamForwardingChannel
- Implements
- Inherited Members
Remarks
Either way's end ends the channel and both its connections: a host that half-closes, shutting its send side to wait for the reply, loses the rest of the reply. Its graceful close ends the tunnel connection's logical stream with its peer, so a reusable connection can carry the next request.
Constructors
StreamForwardingChannel(string, IStreamConnection, IStreamConnection, TransferBufferSize, TrafficMeter?)
Initializes a new instance of the StreamForwardingChannel class.
public StreamForwardingChannel(string channelId, IStreamConnection orgStreamConnection, IStreamConnection tunnelStreamConnection, TransferBufferSize tunnelBufferSize, TrafficMeter? trafficMeter = null)
Parameters
channelIdstringThe channel's ID.
orgStreamConnectionIStreamConnectionThe connection it forwards, which it owns: an app's, on the client, or the one to the destination, on the server.
tunnelStreamConnectionIStreamConnectionThe tunnel connection that carries it, which it owns.
tunnelBufferSizeTransferBufferSizeThe sizes of its buffers toward and from the tunnel, each from 2048 to 81,920 bytes.
trafficMeterTrafficMeterThe meter that counts its bytes and holds it to the session's speed limits, or null.
Exceptions
- ArgumentOutOfRangeException
A buffer size is out of its range.
Properties
ChannelId
Gets the channel's ID.
public string ChannelId { get; }
Property Value
LastActivityTime
Gets when the channel last sent or received, in UTC.
public DateTime LastActivityTime { get; }
Property Value
State
Gets the channel's state.
public PacketChannelState State { get; }
Property Value
Remarks
It is never Disconnecting.
Traffic
Gets what the channel has sent and received.
public Traffic Traffic { get; }
Property Value
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Remarks
The quick close: the channel stops at once and asks its connections to close, with no reuse, without waiting for them.
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 releases both connections; a second call waits for the first one's end.
Start()
Starts the channel, which then reads from its peer.
public void Start()
Remarks
It passes the bytes both ways in the background, and closes gracefully once either way ends.
Exceptions
- ObjectDisposedException
The channel is disposed.
- InvalidOperationException
The channel is already started.
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 channel's ID.