I have a continuous loop sending packets like so from a ConcurrentQueue:
ConcurrentQueue<packet> queue = new ConcurrentQueue<packet>();
while(true){
packet data;
if (!queue.TryPeek(out packet)) continue;
send(data);
queue.TryDequeue(out data); //remove sent packet from the queue
}
Each packet on a particular port has an assigned priority, (null, low, medium, high), etc.
public struct packet
{
public byte[] data;
public uint Length;
public address addr;
public string priority;
}
Which algorithm could I use to send high priority packets first without blocking up the other packets in the queue?
Example:
while(true){
packet data;
if (!queue.TryPeek(out packet)) continue;
foreach(packet x in queue)
{
if(x.priority == "high")
{
send(data);
queue.TryDequeue(out data);
}
}
send(data);
queue.TryDequeue(out data);
}
Example will not work as only the first packet in the queue is sent and removed. I am not sure if this is the correct approach.