Class FairPacketQueue
- Namespace
- VpnHood.Net.PacketTransports
- Assembly
- VpnHood.Net.PacketTransports.dll
Provides a send queue split into 64 lanes by a hash of a packet's ports, so a flow that floods fills mostly its own lane and the packets of other flows need not wait behind its backlog.
public abstract class FairPacketQueue : IDisposable
- Inheritance
-
FairPacketQueue
- Implements
- Inherited Members
Remarks
The busy lanes take turns a packet each, and a lane that was empty is preferred, every other turn at least, such lanes taking turns among themselves too; flows whose ports hash alike share a lane, and the queue promises no latency. The lanes share the capacity, so one flow alone may use all of it, and a full queue drops the oldest packet of its longest lane. A send never waits for room, though it takes a lock; the slots are allocated at construction. A derived class sends each packet in SendQueuedPacketAsync(IpPacket).
Constructors
FairPacketQueue(int)
Initializes the queue and starts its sending loop.
protected FairPacketQueue(int capacity)
Parameters
capacityintThe number of packets the lanes hold together; at least 1.
Exceptions
- ArgumentOutOfRangeException
capacityis less than 1.
Properties
DroppedPackets
Gets the number of packets dropped: pushed out of a full queue, refused once disposed, failed, or discarded when the queue is disposed or starts afresh.
public long DroppedPackets { get; }
Property Value
Name
Gets the name the queue's log lines carry. The default is its type's name.
protected virtual string Name { get; }
Property Value
QueueLength
Gets the number of packets waiting in the queue.
public int QueueLength { get; }
Property Value
Methods
Dispose()
Drops and disposes the packets the queue holds and refuses later sends. A packet being sent is the send's.
public void Dispose()
SendPacketQueued(IpPacket)
Queues a packet in its flow's lane, never waiting: a full queue drops the oldest packet of its longest lane. The queue takes the packet whatever the outcome.
public bool SendPacketQueued(IpPacket ipPacket)
Parameters
ipPacketIpPacketThe packet.
Returns
SendQueuedPacketAsync(IpPacket)
Sends one queued packet on, or disposes it. A throw drops the packet, so do not throw after handing it on. The next packet waits for this call.
protected abstract ValueTask SendQueuedPacketAsync(IpPacket ipPacket)
Parameters
ipPacketIpPacketThe packet, which this call takes.
Returns
- ValueTask
A task that represents the asynchronous operation.