]>
Commit | Line | Data |
---|---|---|
46f4a4d2 | 1 | /* Simple stream test. |
896014f4 | 2 | * |
46f4a4d2 PJ |
3 | * Copyright (C) 2006 Sun Microsystems, Inc. |
4 | * | |
5 | * This file is part of Quagga. | |
6 | * | |
7 | * Quagga is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License as published by the | |
9 | * Free Software Foundation; either version 2, or (at your option) any | |
10 | * later version. | |
11 | * | |
12 | * Quagga is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
896014f4 DL |
17 | * You should have received a copy of the GNU General Public License along |
18 | * with this program; see the file COPYING; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
46f4a4d2 PJ |
20 | */ |
21 | ||
067fca86 | 22 | #include <zebra.h> |
23 | #include <stream.h> | |
24 | #include <thread.h> | |
25 | ||
fb84c629 DL |
26 | #include "printfrr.h" |
27 | ||
6a697154 | 28 | static unsigned long long ham = 0xdeadbeefdeadbeef; |
067fca86 | 29 | struct thread_master *master; |
30 | ||
d62a17ae | 31 | static void print_stream(struct stream *s) |
067fca86 | 32 | { |
d62a17ae | 33 | size_t getp = stream_get_getp(s); |
34 | ||
fb84c629 DL |
35 | printfrr("endp: %zu, readable: %zu, writeable: %zu\n", |
36 | stream_get_endp(s), STREAM_READABLE(s), STREAM_WRITEABLE(s)); | |
d62a17ae | 37 | |
38 | while (STREAM_READABLE(s)) { | |
fb84c629 | 39 | printfrr("0x%x ", *stream_pnt(s)); |
d62a17ae | 40 | stream_forward_getp(s, 1); |
41 | } | |
42 | ||
fb84c629 | 43 | printfrr("\n"); |
d62a17ae | 44 | |
45 | /* put getp back to where it was */ | |
46 | stream_set_getp(s, getp); | |
067fca86 | 47 | } |
48 | ||
d62a17ae | 49 | int main(void) |
067fca86 | 50 | { |
d62a17ae | 51 | struct stream *s; |
52 | ||
53 | s = stream_new(1024); | |
54 | ||
55 | stream_putc(s, ham); | |
56 | stream_putw(s, ham); | |
57 | stream_putl(s, ham); | |
58 | stream_putq(s, ham); | |
59 | ||
60 | print_stream(s); | |
61 | ||
db3c830a | 62 | stream_resize_inplace(&s, stream_get_endp(s)); |
d62a17ae | 63 | |
64 | print_stream(s); | |
65 | ||
fb84c629 DL |
66 | printfrr("c: 0x%hhx\n", stream_getc(s)); |
67 | printfrr("w: 0x%hx\n", stream_getw(s)); | |
68 | printfrr("l: 0x%x\n", stream_getl(s)); | |
69 | printfrr("q: 0x%" PRIx64 "\n", stream_getq(s)); | |
d62a17ae | 70 | |
71 | return 0; | |
067fca86 | 72 | } |