1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-03 04:22:47 -05:00

Utility routines for iterating over a packet queue.

I haven't needed these until now, but I'm about to need to inspect the
entire contents of a packet queue before deciding whether to process
the first item on it.

I've changed the single 'vtable method' in packet queues from get(),
which returned the head of the queue and optionally popped it, to
after() which does the same bug returns the item after a specified
tree node. So if you pass the special end node to after(), then it
behaves like get(), but now you can also use it to retrieve the
successor of a packet.

(Orthogonality says that you can also _pop_ the successor of a packet
by calling after() with prev != pq.end and pop == TRUE. I don't have a
use for that one yet.)
This commit is contained in:
Simon Tatham
2018-10-06 18:42:08 +01:00
parent 0bbe87f11e
commit 36caf03a5b
2 changed files with 23 additions and 18 deletions

View File

@ -71,9 +71,10 @@ static IdempotentCallback ic_pktin_free = {
pktin_free_queue_callback, NULL, FALSE
};
static PktIn *pq_in_get(PacketQueueBase *pqb, int pop)
static PktIn *pq_in_after(PacketQueueBase *pqb,
PacketQueueNode *prev, int pop)
{
PacketQueueNode *node = pqb->end.next;
PacketQueueNode *node = prev->next;
if (node == &pqb->end)
return NULL;
@ -92,9 +93,10 @@ static PktIn *pq_in_get(PacketQueueBase *pqb, int pop)
return container_of(node, PktIn, qnode);
}
static PktOut *pq_out_get(PacketQueueBase *pqb, int pop)
static PktOut *pq_out_after(PacketQueueBase *pqb,
PacketQueueNode *prev, int pop)
{
PacketQueueNode *node = pqb->end.next;
PacketQueueNode *node = prev->next;
if (node == &pqb->end)
return NULL;
@ -111,14 +113,14 @@ void pq_in_init(PktInQueue *pq)
{
pq->pqb.ic = NULL;
pq->pqb.end.next = pq->pqb.end.prev = &pq->pqb.end;
pq->get = pq_in_get;
pq->after = pq_in_after;
}
void pq_out_init(PktOutQueue *pq)
{
pq->pqb.ic = NULL;
pq->pqb.end.next = pq->pqb.end.prev = &pq->pqb.end;
pq->get = pq_out_get;
pq->after = pq_out_after;
}
void pq_in_clear(PktInQueue *pq)