Changeset 8414770 for lib/ior-peek.c


Ignore:
Timestamp:
02/09/10 11:01:16 (12 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
22a9ccc
Parents:
d026488
Message:
  • Updated licensing and documentation for all the IO reader modules
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/ior-peek.c

    rd4a1691 r8414770  
     1/*
     2 * This file is part of libtrace
     3 *
     4 * Copyright (c) 2007,2008,2009,2010 The University of Waikato, Hamilton,
     5 * New Zealand.
     6 *
     7 * Authors: Daniel Lawson
     8 *          Perry Lorier
     9 *          Shane Alcock
     10 *         
     11 * All rights reserved.
     12 *
     13 * This code has been developed by the University of Waikato WAND
     14 * research group. For further information please see http://www.wand.net.nz/
     15 *
     16 * libtrace is free software; you can redistribute it and/or modify
     17 * it under the terms of the GNU General Public License as published by
     18 * the Free Software Foundation; either version 2 of the License, or
     19 * (at your option) any later version.
     20 *
     21 * libtrace is distributed in the hope that it will be useful,
     22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     24 * GNU General Public License for more details.
     25 *
     26 * You should have received a copy of the GNU General Public License
     27 * along with libtrace; if not, write to the Free Software
     28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     29 *
     30 * $Id: format_erf.c 1517 2010-02-08 01:11:04Z salcock $
     31 *
     32 */
     33
    134#include "wandio.h"
    235#include <sys/types.h>
     
    639#include <unistd.h>
    740#include <string.h>
     41
     42/* Libtrace IO module implementing a peeking reader.
     43 *
     44 * Assuming my understanding of Perry's code is correct, this module provides
     45 * generic support for "peeking" that can be used in concert with any other
     46 * implemented IO reader.
     47 *
     48 * The other IO reader is a "child" to the peeking reader and is used to read
     49 * the data into a buffer managed by the peeking reader. Any actual "peeks"
     50 * are serviced from the managed buffer, which means that we do not have to
     51 * manipulate the read offsets directly in zlib or bzip, for instance.
     52 */
    853
    954struct peek_t {
     
    2873        io->source = &peek_source;
    2974
     75        /* Wrap the peeking reader around the "child" */
    3076        DATA(io)->child = child;
    3177        DATA(io)->buffer = NULL;
     
    4490                ret = MIN(len,DATA(io)->length - DATA(io)->offset);
    4591
     92                /* Copy everything we've got into their buffer, and shift our
     93                 * offset so that we don't peek at the data we've read again */
    4694                memcpy(buffer,
    4795                        DATA(io)->buffer + DATA(io)->offset,
     
    5199                len -= ret;
    52100        }
    53         /* Copy the rest of the data from the child */
     101        /* Use the child reader to get the rest of the required data */
    54102        if (len>0) {
    55103                off_t bytes_read =
     
    93141                read_amount += PEEK_SIZE - ((DATA(io)->length + read_amount) % PEEK_SIZE);
    94142                DATA(io)->buffer = realloc(DATA(io)->buffer, DATA(io)->length + read_amount);
     143                /* Use the child reader to read more data into our managed
     144                 * buffer */
    95145                read_amount = wandio_read(DATA(io)->child,
    96146                        DATA(io)->buffer + DATA(io)->length,
     
    105155        }
    106156
    107         /* Right, now return data from the buffer (that now should be large enough, but might
    108          * not be if we hit EOF) */
     157        /* Right, now return data from the buffer (that now should be large
     158         * enough, but might not be if we hit EOF) */
    109159        ret = MIN(len, DATA(io)->length - DATA(io)->offset);
    110160        memcpy(buffer, DATA(io)->buffer + DATA(io)->offset, ret);
     
    114164static off_t peek_tell(io_t *io)
    115165{
     166        /* We don't actually maintain a read offset as such, so we want to
     167         * return the child's read offset */
    116168        return wandio_tell(DATA(io)->child);
    117169}
     
    119171static off_t peek_seek(io_t *io, off_t offset, int whence)
    120172{
     173        /* Again, we don't have a genuine read offset so we need to pass this
     174         * one on to the child */
    121175        return wandio_seek(DATA(io)->child,offset,whence);
    122176}
     
    124178static void peek_close(io_t *io)
    125179{
     180        /* Make sure we close the child that is doing the actual reading! */
    126181        wandio_destroy(DATA(io)->child);
    127182        if (DATA(io)->buffer)
Note: See TracChangeset for help on using the changeset viewer.