Annotation of libelwix/example/test_rbuf.c, revision 1.1.2.1
1.1.2.1 ! misho 1: #include <stdio.h>
! 2: #include <stdlib.h>
! 3: #include <string.h>
! 4: #include <elwix.h>
! 5:
! 6:
! 7: int
! 8: main(int argc, char **argv)
! 9: {
! 10: ringbuf_t rbuf;
! 11: struct iovec iov;
! 12: int res, i;
! 13:
! 14: argc--;
! 15: argv++;
! 16:
! 17: if (rbuf_init(&rbuf, argc ? strtol(argv[0], NULL, 10) : 0)) {
! 18: printf("Error:: rbuf_init(%d) #%d - %s\n", argc, elwix_GetErrno(), elwix_GetError());
! 19: }
! 20:
! 21: argc--;
! 22: argv++;
! 23:
! 24: printf("Result must be 1==%d empty buffer\n", rbuf_dequeue(&rbuf, NULL));
! 25: printf("Buffer is empty? %d\n", rbuf_isempty(&rbuf));
! 26: printf("Buffer is full? %d\n", rbuf_isfull(&rbuf));
! 27: printf("Result enqueue %d\n", rbuf_enqueue(&rbuf, argv[0], argv[0] ? strlen(argv[0]) : 0));
! 28: printf("Buffer is empty? %d\n", rbuf_isempty(&rbuf));
! 29: printf("Buffer is full? %d\n", rbuf_isfull(&rbuf));
! 30: printf("Result dequeue %d\n", (res = rbuf_dequeue(&rbuf, &iov)));
! 31: if (!res)
! 32: printf("iov.iov_base=%p==%p iov.iov_size=%u==%u\n", iov.iov_base, argv[0], iov.iov_len, argv[0] ? strlen(argv[0]) : 0);
! 33: printf("Buffer is empty? %d\n", rbuf_isempty(&rbuf));
! 34: printf("Buffer is full? %d\n", rbuf_isfull(&rbuf));
! 35:
! 36: for (i = 0; i < argc; i++)
! 37: printf("Result enqueue arg#%d %d\n", i, rbuf_enqueue(&rbuf, argv[i], argv[i] ? strlen(argv[i]) : 0));
! 38: printf("Buffer is empty? %d\n", rbuf_isempty(&rbuf));
! 39: printf("Buffer is full? %d\n", rbuf_isfull(&rbuf));
! 40: for (i = 0; i < argc && !(res = rbuf_dequeue(&rbuf, &iov)); i++)
! 41: printf("Result dequeue arg#%d %d = (%d)/%s\n", i, res, iov.iov_len, iov.iov_base);
! 42: printf("Buffer must be empty? 1==%d\n", rbuf_isempty(&rbuf));
! 43: printf("Buffer is full? %d\n", rbuf_isfull(&rbuf));
! 44:
! 45: for (i = 0; i < argc; i++)
! 46: printf("Result enqueue arg#%d %d\n", i, rbuf_enqueue(&rbuf, argv[i], argv[i] ? strlen(argv[i]) : 0));
! 47: printf("Buffer is empty? %d\n", rbuf_isempty(&rbuf));
! 48: printf("Buffer is full? %d\n", rbuf_isfull(&rbuf));
! 49: printf("Purge buffer test\n");
! 50: rbuf_purge(&rbuf);
! 51: printf("Buffer must be empty? 1==%d\n", rbuf_isempty(&rbuf));
! 52: printf("Buffer is full? %d\n", rbuf_isfull(&rbuf));
! 53:
! 54: rbuf_free(&rbuf);
! 55: printf("Result enqueue after free! -1==%d\n", rbuf_enqueue(&rbuf, argv[0], argv[0] ? strlen(argv[0]) : 0));
! 56: printf("Result dequeue after free! -1==%d\n", rbuf_dequeue(&rbuf, &iov));
! 57: return 0;
! 58: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>