Changeset d2d527f
- Timestamp:
- 05/16/05 17:28:41 (16 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:
- dca0810
- Parents:
- 9966f3f
- Location:
- lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/Makefile.am
r828ca90 rd2d527f 4 4 libtrace_la_CFLAGS = @ADD_INCLS@ 5 5 libtrace_la_LIBADD = @ADD_LIBS@ @LTLIBOBJS@ 6 libtrace_la_LDFLAGS=-version-info 2:1 7:0 @ADD_LDFLAGS@6 libtrace_la_LDFLAGS=-version-info 2:18:0 @ADD_LDFLAGS@ 7 7 8 dagapi.c:9 cp @DAG_TOOLS_DIR@/dagapi.c .10 11 dagopts.c:12 cp @DAG_TOOLS_DIR@/dagopts.c .8 #dagapi.c: 9 # cp @DAG_TOOLS_DIR@/dagapi.c . 10 # 11 #dagopts.c: 12 # cp @DAG_TOOLS_DIR@/dagopts.c . -
lib/trace.c
r7b4d443 rd2d527f 168 168 union { 169 169 int fd; 170 #if HAVE_ZLIB171 gzFile *file;172 #else173 170 FILE *file; 174 #endif175 171 #if HAVE_PCAP 176 172 pcap_t *pcap; … … 197 193 double last_ts; 198 194 double start_ts; 195 struct { 196 #define COMP_IBUF_SIZE 65536 197 void *ibuf; 198 void *cbuf; 199 200 uint64_t ibuf_pos; 201 uint64_t cbuf_max; 202 uint64_t cbuf_pos; 203 struct fifo_t *cfifo; 204 } comp; 199 205 }; 200 206 … … 227 233 uint8_t pad[3]; 228 234 }; 235 236 237 /* forward declarations for local functions */ 238 239 int trace_uncompress(void * dest, size_t destLen, const void *source, size_t sourceLen); 240 int trace_comp_read(struct libtrace_t *trace, void *buffer, size_t len); 241 229 242 230 243 #define RP_BUFSIZE 65536 … … 389 402 //(*libtrace)->packet.buffer = 0; 390 403 //(*libtrace)->packet.size = 0; 404 405 (*libtrace)->comp.ibuf = 0; 406 (*libtrace)->comp.cbuf = 0; 407 (*libtrace)->comp.cfifo = create_fifo(1048576); 391 408 392 409 return 1; … … 466 483 { 467 484 #endif 468 #if HAVE_ZLIB 469 libtrace->input.file = gzopen(libtrace->conn_info.path, "r"); 470 #else 485 // We just open files now, because we 486 // do the decompression internally 471 487 libtrace->input.file = fopen(libtrace->conn_info.path, "r"); 472 #endif473 488 } 474 489 break; … … 574 589 #endif 575 590 } else { 576 #if HAVE_ZLIB577 gzclose(libtrace->input.file);578 #else579 591 fclose(libtrace->input.file); 580 #endif581 592 } 582 593 // need to free things! 583 594 destroy_fifo(libtrace->fifo); 595 destroy_fifo(libtrace->comp.cfifo); 596 597 if (libtrace->comp.ibuf) { 598 free(libtrace->comp.ibuf); 599 free(libtrace->comp.cbuf); 600 } 601 584 602 free(libtrace); 585 603 } … … 647 665 default: 648 666 #if HAVE_ZLIB 649 if ((numbytes=gzread(libtrace->input.file, 667 if ((numbytes=trace_comp_read(libtrace, 668 //if ((numbytes=gzread(libtrace->input.file, 650 669 buffer, 651 670 len)) == -1) { 652 perror("gzread");671 //perror("gzread"); 653 672 return -1; 654 673 } … … 758 777 int rlen; 759 778 // read in the trace header 760 if ((numbytes=gzread(libtrace->input.file, 779 if ((numbytes=trace_comp_read(libtrace, 780 //if ((numbytes=gzread(libtrace->input.file, 761 781 buffer, 762 782 dag_record_size)) == -1) { 763 perror("gzread");783 //perror("gzread"); 764 784 return -1; 765 785 } … … 773 793 774 794 // read in the rest of the packet 775 if ((numbytes=gzread(libtrace->input.file, 795 if ((numbytes=trace_comp_read(libtrace, 796 //if ((numbytes=gzread(libtrace->input.file, 776 797 buffer2, 777 798 size)) == -1) { 778 perror("gzread");799 //perror("gzread"); 779 800 return -1; 780 801 } … … 2034 2055 } 2035 2056 2057 //#ifdef HAVE_ZLIB 2058 /* uncompr.c -- decompress a memory buffer 2059 * Copyright (C) 1995-2003 Jean-loup Gailly. 2060 * For conditions of distribution and use, see copyright notice in zlib.h 2061 */ 2062 2063 2064 /* =========================================================================== 2065 Decompresses the source buffer into the destination buffer. sourceLen is 2066 the byte length of the source buffer. Upon entry, destLen is the total 2067 size of the destination buffer, which must be large enough to hold the 2068 entire uncompressed data. (The size of the uncompressed data must have 2069 been saved previously by the compressor and transmitted to the decompressor 2070 by some mechanism outside the scope of this compression library.) 2071 Upon exit, destLen is the actual size of the compressed buffer. 2072 This function can be used to decompress a whole file at once if the 2073 input file is mmap'ed. 2074 2075 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 2076 enough memory, Z_BUF_ERROR if there was not enough room in the output 2077 buffer, or Z_DATA_ERROR if the input data was corrupted. 2078 */ 2079 int trace_uncompress (void *dest, size_t destLen, const void *source, size_t sourceLen) 2080 { 2081 z_stream stream; 2082 int err; 2083 2084 stream.next_in = (Bytef*)source; 2085 stream.avail_in = (uInt)sourceLen; 2086 /* Check for source > 64K on 16-bit machine: */ 2087 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 2088 2089 stream.next_out = dest; 2090 stream.avail_out = destLen; 2091 if ((uLong)stream.avail_out != destLen) return Z_BUF_ERROR; 2092 2093 stream.zalloc = (alloc_func)0; 2094 stream.zfree = (free_func)0; 2095 2096 err = inflateInit(&stream); 2097 if (err != Z_OK) return err; 2098 2099 err = inflate(&stream, Z_FINISH); 2100 if (err != Z_STREAM_END) { 2101 inflateEnd(&stream); 2102 if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) 2103 return Z_DATA_ERROR; 2104 return err; 2105 } 2106 destLen = stream.total_out; 2107 2108 err = inflateEnd(&stream); 2109 return err; 2110 } 2111 2112 2113 int trace_comp_read(struct libtrace_t *trace, void *buffer, size_t len) { 2114 //we want to read len bytes out of the compressed file stored in *fh. 2115 //store this in buffer, and return the number of bytes read. 2116 2117 size_t numbytes = 0; 2118 size_t ret = 0; 2119 2120 if (trace->comp.ibuf == 0) { 2121 trace->comp.ibuf = malloc(COMP_IBUF_SIZE); 2122 trace->comp.cbuf_max = COMP_IBUF_SIZE * 3; 2123 trace->comp.cbuf = malloc(trace->comp.cbuf_max); 2124 } 2125 2126 if (fifo_out_available(trace->comp.cfifo) < len) { 2127 2128 if ((numbytes = fread(trace->comp.ibuf, 2129 COMP_IBUF_SIZE, 2130 1, 2131 trace->input.file)) == 0 ) { 2132 if (feof(trace->input.file)) { 2133 return 0; 2134 } 2135 if (ferror(trace->input.file)) { 2136 perror("fread"); 2137 return -1; 2138 } 2139 } 2140 2141 // attempt to uncompress. This is wrapped up so 2142 // that if the buffer is too small, it resizes 2143 // and loops until it isn't too small 2144 do { 2145 trace->comp.cbuf_pos = trace->comp.cbuf_max; 2146 // trace->comp.cbuf_pos is the size of the compression buffer 2147 ret = trace_incompress(trace->comp.cbuf, 2148 trace->comp.cbuf_pos, 2149 trace->comp.ibuf, 2150 COMP_IBUF_SIZE); 2151 // trace->comp.cbuf_pos is NOW how much of the compression buffer is used; 2152 if (ret == Z_BUF_ERROR) { 2153 trace->comp.cbuf_max *= 2; 2154 trace->comp.cbuf = realloc(trace->comp.cbuf,trace->comp.cbuf_max); 2155 } 2156 } while(ret == Z_BUF_ERROR); 2157 2158 // bad. Exit. 2159 if (ret == Z_DATA_ERROR || ret == Z_MEM_ERROR) { 2160 return -1; 2161 } 2162 2163 fifo_write(trace->comp.cfifo,trace->comp.cbuf,trace->comp.cbuf_pos); 2164 } 2165 2166 if ((numbytes = fifo_out_read(trace->comp.cfifo, buffer, len)) == 0 ) { 2167 fprintf(stderr,"Couldn't read from compressed file, bailing\n"); 2168 return -1; 2169 } 2170 2171 return len; 2172 } 2173 //#endif
Note: See TracChangeset
for help on using the changeset viewer.