1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4
5 #include "tcp_rb.h"
6
7 #define FREE(x) do { free(x); x = NULL; } while (0)
8 #ifndef MIN
9 #define MIN(a, b) ((a) < (b) ? (a) : (b))
10 #endif
11
12 #define PRINTF(f, args...) printf("%s:%d: " f, __FILE__, __LINE__, ##args)
13
14 #define CALL(arg) printf("%s returned %d\n", #arg, arg)
15
main(int argc,char ** argv)16 int main(int argc, char **argv)
17 {
18 uint8_t wbuf[1024] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'};
19 uint8_t rbuf[1024];
20
21 tcprb_t *rb = tcprb_new(10);
22
23 CALL(tcprb_pwrite(rb, wbuf, 2, 0));
24 CALL(tcprb_ppeek(rb, rbuf, 2, 0));
25 PRINTF("Read result: %c%c\n", rbuf[0], rbuf[1]);
26 tcprb_printrb(rb);
27
28 CALL(tcprb_pwrite(rb, wbuf, 2, 3));
29 tcprb_printrb(rb);
30
31 CALL(tcprb_pwrite(rb, wbuf, 2, 2));
32 tcprb_printrb(rb);
33
34 CALL(tcprb_pwrite(rb, wbuf, 2, 9));
35 tcprb_printrb(rb);
36
37 CALL(tcprb_setpile(rb, 2));
38 tcprb_printrb(rb);
39
40 CALL(tcprb_pwrite(rb, wbuf, 2, 11));
41 tcprb_printrb(rb);
42
43 CALL(tcprb_pwrite(rb, wbuf, 3, 6));
44 tcprb_printrb(rb);
45
46 CALL(tcprb_pwrite(rb, wbuf, 8, 4));
47 tcprb_printrb(rb);
48
49 CALL(tcprb_ppeek(rb, rbuf, 10, 2));
50 PRINTF("Read result: %c%c%c%c%c%c%c%c%c%c\n",
51 rbuf[0], rbuf[1], rbuf[2], rbuf[3], rbuf[4],
52 rbuf[5], rbuf[6], rbuf[7], rbuf[8], rbuf[9]);
53
54 CALL(tcprb_setpile(rb, 12));
55 CALL(tcprb_pwrite(rb, wbuf, 1, 21));
56 tcprb_printrb(rb);
57
58 return 0;
59 }
60