1#include <stdio.h>
2
3#include <include/queue.h>
4#include <include/skb_debug.h>
5
6static void skb_send_next(void *arg)
7{
8    struct skb_binding *b = arg;
9
10    struct skb_reply_state* current = dequeue_reply_state(b);
11
12    // If more state in the queue, send them
13    if (current) {
14    	current->rpc_reply(b, current);
15    }
16}
17
18
19void enqueue_reply_state(struct skb_binding *b, struct skb_reply_state* st)
20{
21	if(b->st == NULL) {
22        struct waitset *ws = get_default_waitset();
23		b->register_send(b, ws, MKCONT(skb_send_next, b));
24	}
25
26    struct skb_reply_state** walk = (struct skb_reply_state**) &(b->st);
27    for(; *walk != NULL; walk = &(*walk)->next) {
28    	// continue
29    }
30    *walk = st;
31    st->next = NULL;
32}
33
34
35struct skb_reply_state* dequeue_reply_state(struct skb_binding *b)
36{
37    struct skb_reply_state* head = b->st;
38    b->st = head->next;
39
40    // Reregister for sending, if we need to send more
41    if (b->st != NULL) {
42        struct waitset *ws = get_default_waitset();
43        errval_t err = b->register_send(b, ws, MKCONT(skb_send_next, b));
44        assert(err_is_ok(err));
45    }
46
47    return head;
48}
49
50