]> git.proxmox.com Git - mirror_frr.git/blame - lib/stream.h
Initial revision
[mirror_frr.git] / lib / stream.h
CommitLineData
718e3744 1/*
2 * Packet interface
3 * Copyright (C) 1999 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra 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 * GNU Zebra 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 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 */
22
23#ifndef _ZEBRA_STREAM_H
24#define _ZEBRA_STREAM_H
25
26/* Stream buffer. */
27struct stream
28{
29 struct stream *next;
30
31 unsigned char *data;
32
33 /* Put pointer. */
34 unsigned long putp;
35
36 /* Get pointer. */
37 unsigned long getp;
38
39 /* End of pointer. */
40 unsigned long endp;
41
42 /* Data size. */
43 unsigned long size;
44};
45
46/* First in first out queue structure. */
47struct stream_fifo
48{
49 unsigned long count;
50
51 struct stream *head;
52 struct stream *tail;
53};
54
55/* Utility macros. */
56#define STREAM_PNT(S) ((S)->data + (S)->getp)
57#define STREAM_SIZE(S) ((S)->size)
58#define STREAM_REMAIN(S) ((S)->size - (S)->putp)
59#define STREAM_DATA(S) ((S)->data)
60
61/* Stream prototypes. */
62struct stream *stream_new (size_t);
63void stream_free (struct stream *);
64
65unsigned long stream_get_getp (struct stream *);
66unsigned long stream_get_putp (struct stream *);
67unsigned long stream_get_endp (struct stream *);
68unsigned long stream_get_size (struct stream *);
69u_char *stream_get_data (struct stream *);
70
71void stream_set_getp (struct stream *, unsigned long);
72void stream_set_putp (struct stream *, unsigned long);
73
74void stream_forward (struct stream *, int);
75
76void stream_put (struct stream *, void *, size_t);
77int stream_putc (struct stream *, u_char);
78int stream_putc_at (struct stream *, unsigned long, u_char);
79int stream_putw (struct stream *, u_int16_t);
80int stream_putw_at (struct stream *, unsigned long, u_int16_t);
81int stream_putl (struct stream *, u_int32_t);
82int stream_putl_at (struct stream *, unsigned long, u_int32_t);
83int stream_put_ipv4 (struct stream *, u_int32_t);
84int stream_put_in_addr (struct stream *, struct in_addr *);
85
86void stream_get (void *, struct stream *, size_t);
87u_char stream_getc (struct stream *);
88u_char stream_getc_from (struct stream *, unsigned long);
89u_int16_t stream_getw (struct stream *);
90u_int16_t stream_getw_from (struct stream *, unsigned long);
91u_int32_t stream_getl (struct stream *);
92u_int32_t stream_get_ipv4 (struct stream *);
93
94#undef stream_read
95#undef stream_write
96int stream_read (struct stream *, int, size_t);
97int stream_read_unblock (struct stream *, int, size_t);
98int stream_write (struct stream *, u_char *, size_t);
99
100u_char *stream_pnt (struct stream *);
101void stream_reset (struct stream *);
102int stream_flush (struct stream *, int);
103int stream_empty (struct stream *);
104
105/* Stream fifo. */
106struct stream_fifo *stream_fifo_new ();
107void stream_fifo_push (struct stream_fifo *fifo, struct stream *s);
108struct stream *stream_fifo_pop (struct stream_fifo *fifo);
109struct stream *stream_fifo_head (struct stream_fifo *fifo);
110void stream_fifo_clean (struct stream_fifo *fifo);
111void stream_fifo_free (struct stream_fifo *fifo);
112
113#endif /* _ZEBRA_STREAM_H */