Changeset 14509f0
- Timestamp:
- 04/01/10 15:40:50 (11 years ago)
- 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:
- 81c2da8
- Parents:
- 7283767
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/ior-peek.c
r22a9ccc r14509f0 39 39 #include <unistd.h> 40 40 #include <string.h> 41 #include <assert.h> 41 42 42 43 /* Libtrace IO module implementing a peeking reader. … … 51 52 * manipulate the read offsets directly in zlib or bzip, for instance. 52 53 */ 54 55 /* for O_DIRECT we have to read in multiples of this */ 56 #define MIN_READ_SIZE 4096 57 /* Round reads for peeks into the buffer up to this size */ 58 #define PEEK_SIZE (1024*1024) 53 59 54 60 struct peek_t { … … 90 96 ret = MIN(len,DATA(io)->length - DATA(io)->offset); 91 97 92 /* Copy everything we've got into their buffer, and shift our98 /* Copy anything we've got into their buffer, and shift our 93 99 * offset so that we don't peek at the data we've read again */ 94 100 memcpy(buffer, … … 101 107 /* Use the child reader to get the rest of the required data */ 102 108 if (len>0) { 103 off_t bytes_read = 104 DATA(io)->child->source->read( 105 DATA(io)->child, buffer, len); 106 /* Error? */ 107 if (bytes_read < 1) { 108 /* Return if we have managed to get some data ok */ 109 if (ret > 0) 110 return ret; 111 /* Return the error upstream */ 112 return bytes_read; 109 /* To get here, the buffer must be empty */ 110 assert(DATA(io)->length-DATA(io)->offset == 0); 111 off_t bytes_read; 112 if (len % MIN_READ_SIZE == 0) { 113 bytes_read = DATA(io)->child->source->read( 114 DATA(io)->child, buffer, len); 115 /* Error? */ 116 if (bytes_read < 1) { 117 /* Return if we have managed to get some data ok */ 118 if (ret > 0) 119 return ret; 120 /* Return the error upstream */ 121 return bytes_read; 122 } 123 } 124 else { 125 /* Select the largest of "len", PEEK_SIZE and the current peek buffer size 126 * and then round up to the nearest multiple of MIN_READ_SIZE 127 */ 128 bytes_read = len < PEEK_SIZE ? PEEK_SIZE : len; 129 bytes_read = bytes_read < DATA(io)->length ? DATA(io)->length : bytes_read; 130 bytes_read += MIN_READ_SIZE - (bytes_read % MIN_READ_SIZE); 131 /* Is the current buffer big enough? */ 132 if (DATA(io)->length < bytes_read) { 133 if (DATA(io)->buffer) 134 free(DATA(io)->buffer); 135 DATA(io)->length = bytes_read; 136 DATA(io)->offset = 0; 137 DATA(io)->buffer = malloc(DATA(io)->length); 138 } 139 /* Now actually attempt to read that many bytes */ 140 bytes_read = DATA(io)->child->source->read( 141 DATA(io)->child, DATA(io)->buffer, bytes_read); 142 /* Error? */ 143 if (bytes_read < 1) { 144 if (ret > 0) 145 return ret; 146 return bytes_read; 147 } 148 /* Now grab the number of bytes asked for. */ 149 len = len < bytes_read ? len : bytes_read; 150 memcpy(buffer, DATA(io)->buffer, len); 151 bytes_read = len; 113 152 } 114 153 ret += bytes_read; … … 127 166 } 128 167 129 /* Round reads for peeks into the buffer up to this size */130 #define PEEK_SIZE (1024*1024)131 168 132 169 static off_t peek_peek(io_t *io, void *buffer, off_t len)
Note: See TracChangeset
for help on using the changeset viewer.