Created
September 3, 2012 16:08
-
-
Save JayBeavers/3610343 to your computer and use it in GitHub Desktop.
Simple example of exercising ngx-queue.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See node-gyp for documentation on using this file to build | |
{ | |
"targets": [ | |
{ | |
"target_name": "helloqueue", | |
"sources": [ | |
"helloqueue.c" | |
] | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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