2023-02-08 13:17:09 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-09-16 12:53:49 +02:00
|
|
|
/* Simple stream test.
|
2017-05-13 10:25:29 +02:00
|
|
|
*
|
2014-09-16 12:53:49 +02:00
|
|
|
* Copyright (C) 2006 Sun Microsystems, Inc.
|
|
|
|
*/
|
|
|
|
|
2006-01-10 15:49:04 +01:00
|
|
|
#include <zebra.h>
|
|
|
|
#include <stream.h>
|
2023-03-07 20:22:48 +01:00
|
|
|
#include "frrevent.h"
|
2006-01-10 15:49:04 +01:00
|
|
|
|
2020-03-29 10:17:13 +02:00
|
|
|
#include "printfrr.h"
|
|
|
|
|
2015-10-12 20:33:31 +02:00
|
|
|
static unsigned long long ham = 0xdeadbeefdeadbeef;
|
2023-03-07 20:14:41 +01:00
|
|
|
struct event_loop *master;
|
2006-01-10 15:49:04 +01:00
|
|
|
|
|
|
|
static void print_stream(struct stream *s)
|
|
|
|
{
|
|
|
|
size_t getp = stream_get_getp(s);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-03-29 10:17:13 +02:00
|
|
|
printfrr("endp: %zu, readable: %zu, writeable: %zu\n",
|
|
|
|
stream_get_endp(s), STREAM_READABLE(s), STREAM_WRITEABLE(s));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2006-01-10 15:49:04 +01:00
|
|
|
while (STREAM_READABLE(s)) {
|
2020-03-29 10:17:13 +02:00
|
|
|
printfrr("0x%x ", *stream_pnt(s));
|
2006-01-10 15:49:04 +01:00
|
|
|
stream_forward_getp(s, 1);
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-03-29 10:17:13 +02:00
|
|
|
printfrr("\n");
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2006-01-10 15:49:04 +01:00
|
|
|
/* put getp back to where it was */
|
|
|
|
stream_set_getp(s, getp);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
struct stream *s;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2006-01-10 15:49:04 +01:00
|
|
|
s = stream_new(1024);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2006-01-10 15:49:04 +01:00
|
|
|
stream_putc(s, ham);
|
|
|
|
stream_putw(s, ham);
|
|
|
|
stream_putl(s, ham);
|
|
|
|
stream_putq(s, ham);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2006-01-10 15:49:04 +01:00
|
|
|
print_stream(s);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-08-22 02:22:28 +02:00
|
|
|
stream_resize_inplace(&s, stream_get_endp(s));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2006-01-10 15:49:04 +01:00
|
|
|
print_stream(s);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-03-29 10:17:13 +02:00
|
|
|
printfrr("c: 0x%hhx\n", stream_getc(s));
|
|
|
|
printfrr("w: 0x%hx\n", stream_getw(s));
|
|
|
|
printfrr("l: 0x%x\n", stream_getl(s));
|
|
|
|
printfrr("q: 0x%" PRIx64 "\n", stream_getq(s));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2006-01-10 15:49:04 +01:00
|
|
|
return 0;
|
|
|
|
}
|