aboutsummaryrefslogtreecommitdiffstats
path: root/slirp2/sbuf.h
blob: 05fa01a9bbe8b37920b73c7f55bbc81f679802d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
 * Copyright (c) 1995 Danny Gasparovski.
 * 
 * Please read the file COPYRIGHT for the 
 * terms and conditions of the copyright.
 */

#ifndef _SBUF_H_
#define _SBUF_H_

#include "mbuf.h"
#include <stddef.h>

/* a SBuf is a simple circular buffer used to hold RX and TX data in a struct socket
 */

typedef struct sbuf {
	unsigned  sb_cc;      /* actual chars in buffer */
	unsigned  sb_datalen; /* Length of data  */
	char*     sb_wptr;    /* write pointer. points to where the next
			                                       * bytes should be written in the sbuf */
	char*     sb_rptr;    /* read pointer. points to where the next
                                                                       * byte should be read from the sbuf */
	char*     sb_data;	/* Actual data */
} SBufRec, *SBuf;

void sbuf_free    (SBuf  sb);
void sbuf_drop    (SBuf  sb, int  num);
void sbuf_reserve (SBuf  sb, int  count);
void sbuf_append  (struct socket *so, MBuf  m);
void sbuf_appendsb(SBuf  sb, MBuf  m);
void sbuf_copy    (SBuf  sb, int  offset, int  length, char *to);

#define sbuf_flush(sb) sbuf_drop((sb),(sb)->sb_cc)
#define sbuf_space(sb) ((sb)->sb_datalen - (sb)->sb_cc)

#endif