Changeset a22c979
- Timestamp:
- 10/26/04 14:56:57 (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:
- 678048a
- Parents:
- 59c31da
- Location:
- lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/libtrace.h
r6cd7c20 ra22c979 82 82 struct libtrace_packet_t { 83 83 struct libtrace_t *trace; 84 char buffer[LIBTRACE_PACKET_BUFSIZE]; 84 void *buffer; 85 //char buffer[LIBTRACE_PACKET_BUFSIZE]; 85 86 size_t size; 86 87 uint8_t status; -
lib/trace.c
r59c31da ra22c979 131 131 } input; 132 132 struct fifo_t *fifo; 133 void *buf; 133 struct { 134 void *buf; 135 unsigned bottom; 136 unsigned top; 137 unsigned diff; 138 unsigned curr; 139 unsigned offset; 140 } dag; 134 141 struct { 135 142 void *buffer; … … 405 412 exit(0); 406 413 } 407 if((libtrace-> buf = dag_mmap(libtrace->input.fd)) == MAP_FAILED) {414 if((libtrace->dag.buf = dag_mmap(libtrace->input.fd)) == MAP_FAILED) { 408 415 fprintf(stderr,"Cannot mmap DAG %s: %m\n", libtrace->conn_info.path,errno); 409 416 exit(0); … … 448 455 static int trace_read(struct libtrace_t *libtrace, void *buffer, size_t len) { 449 456 int numbytes; 450 static unsigned bottom = 0, top, diff, curr = 0, scan;451 457 static short lctr = 0; 452 458 struct dag_record_t *recptr = 0; … … 480 486 case DAG: 481 487 482 top = dag_offset(libtrace->input.fd, 483 &bottom, 488 libtrace->dag.top = dag_offset( 489 libtrace->input.fd, 490 &(libtrace->dag.bottom), 484 491 0); 485 diff = top - bottom; 492 libtrace->dag.diff = libtrace->dag.top - 493 libtrace->dag.bottom; 486 494 487 495 //recptr = (dag_record_t *) ((void *)libtrace->buf + (bottom + curr)); … … 489 497 490 498 491 memcpy(buffer,(void *)(libtrace->buf + (bottom + curr)),diff);499 //memcpy(buffer,(void *)(libtrace->buf + (bottom + curr)),diff); 492 500 493 501 //buffer=libtrace->buf + (bottom + curr); 494 502 495 numbytes=diff; 496 bottom=top; 503 numbytes=libtrace->dag.diff; 504 libtrace->dag.bottom = libtrace->dag.top; 505 libtrace->dag.offset = 0; 497 506 498 507 break; … … 532 541 char buf[RP_BUFSIZE]; 533 542 struct pcap_pkthdr pcaphdr; 543 dag_record_t *erfptr; 534 544 const u_char *pcappkt; 535 545 int read_required = 0; … … 541 551 assert(libtrace); 542 552 assert(packet); 553 if(packet->buffer == 0) { 554 packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE); 555 } 543 556 544 557 //bzero(buffer,len); … … 589 602 return sizeof(dag_record_t) + numbytes; 590 603 } 591 604 605 if (libtrace->format == DAG) { 606 // we can do some zero-copy stuff here 607 while(1) { 608 if (libtrace->dag.diff == 0) { 609 if ((numbytes = trace_read(libtrace,buf,RP_BUFSIZE)) <= 0) 610 return numbytes; 611 } 612 // DAG always gives us whole packets. 613 614 erfptr = (dag_record_t *) (libtrace->dag.buf + libtrace->dag.offset); 615 size = ntohs(erfptr->rlen); 616 617 assert( (size - sizeof(dag_record_t)) < LIBTRACE_PACKET_BUFSIZE); 618 619 packet->buffer = (void *)erfptr; 620 packet->size = size; 621 libtrace->dag.offset += size; 622 libtrace->dag.diff -= size; 623 624 return (size); 625 626 } 627 } 592 628 do { 593 629 if (fifo_out_available(libtrace->fifo) == 0 || read_required) {
Note: See TracChangeset
for help on using the changeset viewer.