• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 1995 Danny Gasparovski.
3  *
4  * Please read the file COPYRIGHT for the
5  * terms and conditions of the copyright.
6  */
7 
8 #ifndef _SBUF_H_
9 #define _SBUF_H_
10 
11 #include "mbuf.h"
12 #include <stddef.h>
13 
14 /* a SBuf is a simple circular buffer used to hold RX and TX data in a struct socket
15  */
16 
17 typedef struct sbuf {
18 	unsigned  sb_cc;      /* actual chars in buffer */
19 	unsigned  sb_datalen; /* Length of data  */
20 	char*     sb_wptr;    /* write pointer. points to where the next
21 			                                       * bytes should be written in the sbuf */
22 	char*     sb_rptr;    /* read pointer. points to where the next
23                                                                        * byte should be read from the sbuf */
24 	char*     sb_data;	/* Actual data */
25 } SBufRec, *SBuf;
26 
27 void sbuf_free    (SBuf  sb);
28 void sbuf_drop    (SBuf  sb, int  num);
29 void sbuf_reserve (SBuf  sb, int  count);
30 void sbuf_append  (struct socket *so, MBuf  m);
31 void sbuf_appendsb(SBuf  sb, MBuf  m);
32 void sbuf_copy    (SBuf  sb, int  offset, int  length, char *to);
33 
34 #define sbuf_flush(sb) sbuf_drop((sb),(sb)->sb_cc)
35 #define sbuf_space(sb) ((sb)->sb_datalen - (sb)->sb_cc)
36 
37 #endif
38