Create a gist now

Instantly share code, notes, and snippets.

Simple example of exercising ngx-queue.h
// See node-gyp for documentation on using this file to build
{
"targets": [
{
"target_name": "helloqueue",
"sources": [
"helloqueue.c"
]
}
]
}
#include <stdio.h>
#include <stddef.h>
#include <ngx-queue.h>
struct queue_element_s {
ngx_queue_t queue;
int data;
};
typedef struct queue_element_s queue_element_t;
int main() {
ngx_queue_t root;
ngx_queue_init(&root);
printf("Empty: %d\n", ngx_queue_empty(&root));
queue_element_t one;
one.data = 1;
ngx_queue_init(&one.queue);
ngx_queue_insert_tail(&root, &one.queue);
printf("Inserted Tail\n");
printf("Empty: %d\n", ngx_queue_empty(&root));
queue_element_t two;
two.data = 2;
ngx_queue_init(&two.queue);
ngx_queue_insert_tail(&root, &two.queue);
ngx_queue_t* q = ngx_queue_head(&root);
queue_element_t* pElement = ngx_queue_data(q, queue_element_t, queue);
printf("Head %d\n", pElement->data);
ngx_queue_remove(q);
printf("Removed\n");
printf("Empty: %d\n", ngx_queue_empty(&root));
q = ngx_queue_head(&root);
pElement = ngx_queue_data(q, queue_element_t, queue);
printf("Head %d\n", pElement->data);
ngx_queue_remove(q);
printf("Removed\n");
printf("Empty: %d\n", ngx_queue_empty(&root));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment