xref: /csrg-svn/usr.bin/telnet/ring.h (revision 62311)
132380Sminshall /*
2*62311Sbostic  * Copyright (c) 1988, 1993
3*62311Sbostic  *	The Regents of the University of California.  All rights reserved.
433685Sbostic  *
542770Sbostic  * %sccs.include.redist.c%
633685Sbostic  *
7*62311Sbostic  *	@(#)ring.h	8.1 (Berkeley) 06/06/93
833685Sbostic  */
933685Sbostic 
1046808Sdab #if defined(P)
1146808Sdab # undef P
1246808Sdab #endif
1346808Sdab 
1446808Sdab #if defined(__STDC__) || defined(LINT_ARGS)
1546808Sdab # define	P(x)	x
1646808Sdab #else
1746808Sdab # define	P(x)	()
1846808Sdab #endif
1946808Sdab 
2033685Sbostic /*
2132528Sminshall  * This defines a structure for a ring buffer.
2232380Sminshall  *
2332528Sminshall  * The circular buffer has two parts:
2432380Sminshall  *(((
2532528Sminshall  *	full:	[consume, supply)
2632528Sminshall  *	empty:	[supply, consume)
2732380Sminshall  *]]]
2832380Sminshall  *
2932380Sminshall  */
3032380Sminshall typedef struct {
3146808Sdab     unsigned char	*consume,	/* where data comes out of */
3246808Sdab 			*supply,	/* where data comes in to */
3346808Sdab 			*bottom,	/* lowest address in buffer */
3446808Sdab 			*top,		/* highest address+1 in buffer */
3546808Sdab 			*mark;		/* marker (user defined) */
3660149Sdab #ifdef	ENCRYPTION
3746808Sdab     unsigned char	*clearto;	/* Data to this point is clear text */
3846808Sdab     unsigned char	*encryyptedto;	/* Data is encrypted to here */
3960149Sdab #endif	/* ENCRYPTION */
4032380Sminshall     int		size;		/* size in bytes of buffer */
4132528Sminshall     u_long	consumetime,	/* help us keep straight full, empty, etc. */
4232528Sminshall 		supplytime;
4332380Sminshall } Ring;
4432380Sminshall 
4532380Sminshall /* Here are some functions and macros to deal with the ring buffer */
4632380Sminshall 
4732381Sminshall /* Initialization routine */
4832381Sminshall extern int
4946808Sdab 	ring_init P((Ring *ring, unsigned char *buffer, int count));
5032381Sminshall 
5132380Sminshall /* Data movement routines */
5232380Sminshall extern void
5346808Sdab 	ring_supply_data P((Ring *ring, unsigned char *buffer, int count));
5444360Sborman #ifdef notdef
5544360Sborman extern void
5646808Sdab 	ring_consume_data P((Ring *ring, unsigned char *buffer, int count));
5744360Sborman #endif
5832380Sminshall 
5932380Sminshall /* Buffer state transition routines */
6032380Sminshall extern void
6146808Sdab 	ring_supplied P((Ring *ring, int count)),
6246808Sdab 	ring_consumed P((Ring *ring, int count));
6332380Sminshall 
6432380Sminshall /* Buffer state query routines */
6532380Sminshall extern int
6646808Sdab 	ring_empty_count P((Ring *ring)),
6746808Sdab 	ring_empty_consecutive P((Ring *ring)),
6846808Sdab 	ring_full_count P((Ring *ring)),
6946808Sdab 	ring_full_consecutive P((Ring *ring));
7032380Sminshall 
7160149Sdab #ifdef	ENCRYPTION
7234848Sminshall extern void
7346808Sdab 	ring_encrypt P((Ring *ring, void (*func)())),
7446808Sdab 	ring_clearto P((Ring *ring));
7560149Sdab #endif	/* ENCRYPTION */
7634848Sminshall 
7734848Sminshall extern void
7834848Sminshall     ring_clear_mark(),
7934848Sminshall     ring_mark();
80