xref: /csrg-svn/usr.bin/telnet/ring.h (revision 32380)
1*32380Sminshall /*
2*32380Sminshall  * This defines a structure for a receive or send ring buffer.
3*32380Sminshall  *
4*32380Sminshall  * The circular buffer actually has three parts:
5*32380Sminshall  *(((
6*32380Sminshall  *	full, sent, not acked:	[ack, send)
7*32380Sminshall  *	full, not sent:		[send, add)
8*32380Sminshall  *	empty:			[add, ack)
9*32380Sminshall  *]]]
10*32380Sminshall  *
11*32380Sminshall  * Any given byte will go through "empty" -> "send" -> "ack" -> "empty"
12*32380Sminshall  * as data is moved through it.  The transition from "ack" to "empty"
13*32380Sminshall  * may occur instantaneously (as in the case of sending data up to another
14*32380Sminshall  * process).
15*32380Sminshall  */
16*32380Sminshall typedef struct {
17*32380Sminshall     char	*ack,		/* where you can't add at */
18*32380Sminshall     		*send,		/* where data comes out of */
19*32380Sminshall     		*add,		/* where data comes in to */
20*32380Sminshall 		*bottom,	/* lowest address in buffer */
21*32380Sminshall 		*top;		/* highest address+1 in buffer */
22*32380Sminshall     int		size;		/* size in bytes of buffer */
23*32380Sminshall     u_long	acktime,	/* the relations between these clocks */
24*32380Sminshall 		sendtime,	/* help us keep straight full, empty, etc. */
25*32380Sminshall 		addtime;
26*32380Sminshall } Ring;
27*32380Sminshall 
28*32380Sminshall /* Here are some functions and macros to deal with the ring buffer */
29*32380Sminshall 
30*32380Sminshall 
31*32380Sminshall #if	defined(LINT_ARGS)
32*32380Sminshall 
33*32380Sminshall /* Data movement routines */
34*32380Sminshall extern void
35*32380Sminshall 	ring_add_data(Ring *ring, char *buffer, int count),
36*32380Sminshall 	ring_send_data(Ring *ring, char *buffer, int count);
37*32380Sminshall 
38*32380Sminshall /* Buffer state transition routines */
39*32380Sminshall extern void
40*32380Sminshall 	ring_added(Ring *ring, int count),
41*32380Sminshall 	ring_sent(Ring *ring, int count),
42*32380Sminshall 	ring_acked(Ring *ring, int count);
43*32380Sminshall 
44*32380Sminshall /* Buffer state query routines */
45*32380Sminshall extern int
46*32380Sminshall 	ring_empty_count(Ring *ring),
47*32380Sminshall 	ring_empty_consecutive(Ring *ring),
48*32380Sminshall 	ring_unsent_count(Ring *ring),
49*32380Sminshall 	ring_unsent_consecutive(Ring *ring),
50*32380Sminshall 	ring_unacked_count(Ring *ring);
51*32380Sminshall 
52*32380Sminshall #endif	/* defined(LINT_ARGS) */
53