xref: /csrg-svn/usr.bin/telnet/ring.h (revision 32381)
132380Sminshall /*
232380Sminshall  * This defines a structure for a receive or send ring buffer.
332380Sminshall  *
432380Sminshall  * The circular buffer actually has three parts:
532380Sminshall  *(((
632380Sminshall  *	full, sent, not acked:	[ack, send)
732380Sminshall  *	full, not sent:		[send, add)
832380Sminshall  *	empty:			[add, ack)
932380Sminshall  *]]]
1032380Sminshall  *
1132380Sminshall  * Any given byte will go through "empty" -> "send" -> "ack" -> "empty"
1232380Sminshall  * as data is moved through it.  The transition from "ack" to "empty"
1332380Sminshall  * may occur instantaneously (as in the case of sending data up to another
1432380Sminshall  * process).
1532380Sminshall  */
1632380Sminshall typedef struct {
1732380Sminshall     char	*ack,		/* where you can't add at */
1832380Sminshall     		*send,		/* where data comes out of */
1932380Sminshall     		*add,		/* where data comes in to */
2032380Sminshall 		*bottom,	/* lowest address in buffer */
2132380Sminshall 		*top;		/* highest address+1 in buffer */
2232380Sminshall     int		size;		/* size in bytes of buffer */
2332380Sminshall     u_long	acktime,	/* the relations between these clocks */
2432380Sminshall 		sendtime,	/* help us keep straight full, empty, etc. */
2532380Sminshall 		addtime;
2632380Sminshall } Ring;
2732380Sminshall 
2832380Sminshall /* Here are some functions and macros to deal with the ring buffer */
2932380Sminshall 
3032380Sminshall 
3132380Sminshall #if	defined(LINT_ARGS)
3232380Sminshall 
33*32381Sminshall /* Initialization routine */
34*32381Sminshall extern int
35*32381Sminshall 	ring_init(Ring *ring, char *buffer, int count);
36*32381Sminshall 
3732380Sminshall /* Data movement routines */
3832380Sminshall extern void
3932380Sminshall 	ring_add_data(Ring *ring, char *buffer, int count),
4032380Sminshall 	ring_send_data(Ring *ring, char *buffer, int count);
4132380Sminshall 
4232380Sminshall /* Buffer state transition routines */
4332380Sminshall extern void
4432380Sminshall 	ring_added(Ring *ring, int count),
4532380Sminshall 	ring_sent(Ring *ring, int count),
4632380Sminshall 	ring_acked(Ring *ring, int count);
4732380Sminshall 
4832380Sminshall /* Buffer state query routines */
4932380Sminshall extern int
5032380Sminshall 	ring_empty_count(Ring *ring),
5132380Sminshall 	ring_empty_consecutive(Ring *ring),
5232380Sminshall 	ring_unsent_count(Ring *ring),
5332380Sminshall 	ring_unsent_consecutive(Ring *ring),
5432380Sminshall 	ring_unacked_count(Ring *ring);
5532380Sminshall 
5632380Sminshall #endif	/* defined(LINT_ARGS) */
57