1 /* 2 * Copyright (c) 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)ring.h 8.1 (Berkeley) 06/06/93 8 */ 9 10 #if defined(P) 11 # undef P 12 #endif 13 14 #if defined(__STDC__) || defined(LINT_ARGS) 15 # define P(x) x 16 #else 17 # define P(x) () 18 #endif 19 20 /* 21 * This defines a structure for a ring buffer. 22 * 23 * The circular buffer has two parts: 24 *((( 25 * full: [consume, supply) 26 * empty: [supply, consume) 27 *]]] 28 * 29 */ 30 typedef struct { 31 unsigned char *consume, /* where data comes out of */ 32 *supply, /* where data comes in to */ 33 *bottom, /* lowest address in buffer */ 34 *top, /* highest address+1 in buffer */ 35 *mark; /* marker (user defined) */ 36 #ifdef ENCRYPTION 37 unsigned char *clearto; /* Data to this point is clear text */ 38 unsigned char *encryyptedto; /* Data is encrypted to here */ 39 #endif /* ENCRYPTION */ 40 int size; /* size in bytes of buffer */ 41 u_long consumetime, /* help us keep straight full, empty, etc. */ 42 supplytime; 43 } Ring; 44 45 /* Here are some functions and macros to deal with the ring buffer */ 46 47 /* Initialization routine */ 48 extern int 49 ring_init P((Ring *ring, unsigned char *buffer, int count)); 50 51 /* Data movement routines */ 52 extern void 53 ring_supply_data P((Ring *ring, unsigned char *buffer, int count)); 54 #ifdef notdef 55 extern void 56 ring_consume_data P((Ring *ring, unsigned char *buffer, int count)); 57 #endif 58 59 /* Buffer state transition routines */ 60 extern void 61 ring_supplied P((Ring *ring, int count)), 62 ring_consumed P((Ring *ring, int count)); 63 64 /* Buffer state query routines */ 65 extern int 66 ring_empty_count P((Ring *ring)), 67 ring_empty_consecutive P((Ring *ring)), 68 ring_full_count P((Ring *ring)), 69 ring_full_consecutive P((Ring *ring)); 70 71 #ifdef ENCRYPTION 72 extern void 73 ring_encrypt P((Ring *ring, void (*func)())), 74 ring_clearto P((Ring *ring)); 75 #endif /* ENCRYPTION */ 76 77 extern void 78 ring_clear_mark(), 79 ring_mark(); 80