132380Sminshall /* 233685Sbostic * Copyright (c) 1988 Regents of the University of California. 333685Sbostic * All rights reserved. 433685Sbostic * 542770Sbostic * %sccs.include.redist.c% 633685Sbostic * 7*46808Sdab * @(#)ring.h 5.2 (Berkeley) 03/01/91 833685Sbostic */ 933685Sbostic 10*46808Sdab #if defined(P) 11*46808Sdab # undef P 12*46808Sdab #endif 13*46808Sdab 14*46808Sdab #if defined(__STDC__) || defined(LINT_ARGS) 15*46808Sdab # define P(x) x 16*46808Sdab #else 17*46808Sdab # define P(x) () 18*46808Sdab #endif 19*46808Sdab 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 { 31*46808Sdab unsigned char *consume, /* where data comes out of */ 32*46808Sdab *supply, /* where data comes in to */ 33*46808Sdab *bottom, /* lowest address in buffer */ 34*46808Sdab *top, /* highest address+1 in buffer */ 35*46808Sdab *mark; /* marker (user defined) */ 36*46808Sdab #if defined(ENCRYPT) 37*46808Sdab unsigned char *clearto; /* Data to this point is clear text */ 38*46808Sdab unsigned char *encryyptedto; /* Data is encrypted to here */ 39*46808Sdab #endif 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 49*46808Sdab ring_init P((Ring *ring, unsigned char *buffer, int count)); 5032381Sminshall 5132380Sminshall /* Data movement routines */ 5232380Sminshall extern void 53*46808Sdab ring_supply_data P((Ring *ring, unsigned char *buffer, int count)); 5444360Sborman #ifdef notdef 5544360Sborman extern void 56*46808Sdab ring_consume_data P((Ring *ring, unsigned char *buffer, int count)); 5744360Sborman #endif 5832380Sminshall 5932380Sminshall /* Buffer state transition routines */ 6032380Sminshall extern void 61*46808Sdab ring_supplied P((Ring *ring, int count)), 62*46808Sdab ring_consumed P((Ring *ring, int count)); 6332380Sminshall 6432380Sminshall /* Buffer state query routines */ 6532380Sminshall extern int 66*46808Sdab ring_empty_count P((Ring *ring)), 67*46808Sdab ring_empty_consecutive P((Ring *ring)), 68*46808Sdab ring_full_count P((Ring *ring)), 69*46808Sdab ring_full_consecutive P((Ring *ring)); 7032380Sminshall 71*46808Sdab #if defined(ENCRYPT) 7234848Sminshall extern void 73*46808Sdab ring_encrypt P((Ring *ring, void (*func)())), 74*46808Sdab ring_clearto P((Ring *ring)); 7544360Sborman #endif 7634848Sminshall 7734848Sminshall extern void 7834848Sminshall ring_clear_mark(), 7934848Sminshall ring_mark(); 80