]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
46f4a4d2 | 2 | /* Simple stream test. |
896014f4 | 3 | * |
46f4a4d2 | 4 | * Copyright (C) 2006 Sun Microsystems, Inc. |
46f4a4d2 PJ |
5 | */ |
6 | ||
067fca86 | 7 | #include <zebra.h> |
8 | #include <stream.h> | |
24a58196 | 9 | #include "frrevent.h" |
067fca86 | 10 | |
fb84c629 DL |
11 | #include "printfrr.h" |
12 | ||
6a697154 | 13 | static unsigned long long ham = 0xdeadbeefdeadbeef; |
cd9d0537 | 14 | struct event_loop *master; |
067fca86 | 15 | |
d62a17ae | 16 | static void print_stream(struct stream *s) |
067fca86 | 17 | { |
d62a17ae | 18 | size_t getp = stream_get_getp(s); |
19 | ||
fb84c629 DL |
20 | printfrr("endp: %zu, readable: %zu, writeable: %zu\n", |
21 | stream_get_endp(s), STREAM_READABLE(s), STREAM_WRITEABLE(s)); | |
d62a17ae | 22 | |
23 | while (STREAM_READABLE(s)) { | |
fb84c629 | 24 | printfrr("0x%x ", *stream_pnt(s)); |
d62a17ae | 25 | stream_forward_getp(s, 1); |
26 | } | |
27 | ||
fb84c629 | 28 | printfrr("\n"); |
d62a17ae | 29 | |
30 | /* put getp back to where it was */ | |
31 | stream_set_getp(s, getp); | |
067fca86 | 32 | } |
33 | ||
d62a17ae | 34 | int main(void) |
067fca86 | 35 | { |
d62a17ae | 36 | struct stream *s; |
37 | ||
38 | s = stream_new(1024); | |
39 | ||
40 | stream_putc(s, ham); | |
41 | stream_putw(s, ham); | |
42 | stream_putl(s, ham); | |
43 | stream_putq(s, ham); | |
44 | ||
45 | print_stream(s); | |
46 | ||
db3c830a | 47 | stream_resize_inplace(&s, stream_get_endp(s)); |
d62a17ae | 48 | |
49 | print_stream(s); | |
50 | ||
fb84c629 DL |
51 | printfrr("c: 0x%hhx\n", stream_getc(s)); |
52 | printfrr("w: 0x%hx\n", stream_getw(s)); | |
53 | printfrr("l: 0x%x\n", stream_getl(s)); | |
54 | printfrr("q: 0x%" PRIx64 "\n", stream_getq(s)); | |
d62a17ae | 55 | |
56 | return 0; | |
067fca86 | 57 | } |