157416Smarkm/*
257416Smarkm * Copyright (c) 1988, 1993
357416Smarkm *	The Regents of the University of California.  All rights reserved.
457416Smarkm *
557416Smarkm * Redistribution and use in source and binary forms, with or without
657416Smarkm * modification, are permitted provided that the following conditions
757416Smarkm * are met:
857416Smarkm * 1. Redistributions of source code must retain the above copyright
957416Smarkm *    notice, this list of conditions and the following disclaimer.
1057416Smarkm * 2. Redistributions in binary form must reproduce the above copyright
1157416Smarkm *    notice, this list of conditions and the following disclaimer in the
1257416Smarkm *    documentation and/or other materials provided with the distribution.
1357416Smarkm * 3. All advertising materials mentioning features or use of this software
1457416Smarkm *    must display the following acknowledgement:
1557416Smarkm *	This product includes software developed by the University of
1657416Smarkm *	California, Berkeley and its contributors.
1757416Smarkm * 4. Neither the name of the University nor the names of its contributors
1857416Smarkm *    may be used to endorse or promote products derived from this software
1957416Smarkm *    without specific prior written permission.
2057416Smarkm *
2157416Smarkm * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2257416Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2357416Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2457416Smarkm * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2557416Smarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2657416Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2757416Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2857416Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2957416Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3057416Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3157416Smarkm * SUCH DAMAGE.
3257416Smarkm *
3357416Smarkm *	@(#)ring.h	8.1 (Berkeley) 6/6/93
3457416Smarkm */
3557416Smarkm
36233294Sstas/* $Id$ */
3757416Smarkm
3857416Smarkm/*
3957416Smarkm * This defines a structure for a ring buffer.
4057416Smarkm *
4157416Smarkm * The circular buffer has two parts:
4257416Smarkm *(((
4357416Smarkm *	full:	[consume, supply)
4457416Smarkm *	empty:	[supply, consume)
4557416Smarkm *]]]
4657416Smarkm *
4757416Smarkm */
4857416Smarkmtypedef struct {
4957416Smarkm    unsigned char	*consume,	/* where data comes out of */
5057416Smarkm			*supply,	/* where data comes in to */
5157416Smarkm			*bottom,	/* lowest address in buffer */
5257416Smarkm			*top,		/* highest address+1 in buffer */
5357416Smarkm			*mark;		/* marker (user defined) */
5457416Smarkm#if	defined(ENCRYPTION)
5557416Smarkm    unsigned char	*clearto;	/* Data to this point is clear text */
5657416Smarkm    unsigned char	*encryyptedto;	/* Data is encrypted to here */
5757416Smarkm#endif
5857416Smarkm    int		size;		/* size in bytes of buffer */
5957416Smarkm    u_long	consumetime,	/* help us keep straight full, empty, etc. */
6057416Smarkm		supplytime;
6157416Smarkm} Ring;
6257416Smarkm
6357416Smarkm/* Here are some functions and macros to deal with the ring buffer */
6457416Smarkm
6557416Smarkm/* Initialization routine */
6657416Smarkmextern int
6757416Smarkm	ring_init (Ring *ring, unsigned char *buffer, int count);
6857416Smarkm
6957416Smarkm/* Data movement routines */
7057416Smarkmextern void
7157416Smarkm	ring_supply_data (Ring *ring, unsigned char *buffer, int count);
7257416Smarkm#ifdef notdef
7357416Smarkmextern void
7457416Smarkm	ring_consume_data (Ring *ring, unsigned char *buffer, int count);
7557416Smarkm#endif
7657416Smarkm
7757416Smarkm/* Buffer state transition routines */
7857416Smarkmextern void
7957416Smarkm	ring_supplied (Ring *ring, int count),
8057416Smarkm	ring_consumed (Ring *ring, int count);
8157416Smarkm
8257416Smarkm/* Buffer state query routines */
8357416Smarkmextern int
8457416Smarkm	ring_empty_count (Ring *ring),
8557416Smarkm	ring_empty_consecutive (Ring *ring),
8657416Smarkm	ring_full_count (Ring *ring),
8757416Smarkm	ring_full_consecutive (Ring *ring);
8857416Smarkm
8957416Smarkm#if	defined(ENCRYPTION)
9057416Smarkmextern void
9157416Smarkm	ring_encrypt (Ring *ring, void (*func)(unsigned char *, int)),
9257416Smarkm	ring_clearto (Ring *ring);
9357416Smarkm#endif
9457416Smarkm
9557416Smarkmextern int ring_at_mark(Ring *ring);
9657416Smarkm
9757416Smarkmextern void
9857416Smarkm    ring_clear_mark(Ring *ring),
9957416Smarkm    ring_mark(Ring *ring);
100