1/* @(#) header of data-stream cache for udpxy 2 * 3 * Copyright 2008-2011 Pavel V. Cherenkov (pcherenkov@gmail.com) 4 * 5 * This file is part of udpxy. 6 * 7 * udpxy is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * udpxy is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with udpxy. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21#ifndef UDPXY_CACHEH_06122008 22#define UDPXY_CACHEH_06122008 23 24#include <sys/types.h> 25 26#include "dpkt.h" 27 28extern FILE* g_flog; 29 30struct chunk { 31 char* data; 32 size_t length; 33 size_t used_length; 34 35 struct dstream_ctx 36 spc; 37 38 39 struct chunk* next; 40}; 41 42struct dscache; 43 44#define ERR_CACHE_END 20 /* reached end of data */ 45#define ERR_CACHE_ALLOC 21 /* cannot allocate memory */ 46#define ERR_CACHE_BADDATA 22 /* data at a cache's head is invalid */ 47#define ERR_CACHE_INTRNL 99 /* internal error */ 48 49#ifdef __cplusplus 50extern "C" { 51#endif 52 53/* initialize the cache 54 */ 55struct dscache* 56dscache_init( size_t maxlen, struct dstream_ctx* spc, 57 size_t chunklen, unsigned nchunks ); 58 59 60/* get chunk at R-head, allocate new one if needed 61 */ 62struct chunk* 63dscache_rget( struct dscache* cache, int* error ); 64 65 66/* specify length of the used chunk's portion 67 */ 68int 69dscache_rset( struct dscache* cache, size_t usedlen ); 70 71 72/* specify length of the used chunk's portion 73 * and advance R-head 74 */ 75int 76dscache_rnext( struct dscache* cache, size_t usedlen ); 77 78 79/* get a chunk at W-head 80 */ 81struct chunk* 82dscache_wget( struct dscache* cache, int* error ); 83 84 85/* advance (W-head) to the next chunk, 86 * release unneeded resources 87 */ 88int 89dscache_wnext( struct dscache* cache, int* error ); 90 91 92/* release all resources from cache 93 */ 94void 95dscache_free( struct dscache* cache ); 96 97 98#ifdef __cplusplus 99} 100#endif 101 102 103#endif /* UDPXY_CACHEH_06122008 */ 104 105/* __EOF__*/ 106 107 108