Changeset 468
- Timestamp:
- 09/02/05 15:11:12 (8 years ago)
- Files:
-
- 1 modified
-
trunk/pdns/pdns/dnsreplay-mindex.cc (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pdns/pdns/dnsreplay-mindex.cc
r464 r468 21 21 What to do with timeouts. We keep around at most 65536 outstanding answers. 22 22 */ 23 24 25 /* 26 mental_clock=0; 27 for(;;) { 28 29 do { 30 read a packet 31 send a packet 32 } while(time_of_last_packet_sent < mental_clock) 33 mental_clock=time_of_last_packet_sent; 34 35 wait for a response packet for 0.1 seconds 36 note how much time has passed 37 mental_clock+=time_passed; 38 } 39 40 */ 23 41 24 42 #include <pcap.h> … … 44 62 bool s_quiet=true; 45 63 64 65 void normalizeTV(struct timeval& tv) 66 { 67 if(tv.tv_usec > 1000000) { 68 ++tv.tv_sec; 69 tv.tv_usec-=1000000; 70 } 71 else if(tv.tv_usec < 0) { 72 --tv.tv_sec; 73 tv.tv_usec+=1000000; 74 } 75 } 76 77 const struct timeval operator+(const struct timeval& lhs, const struct timeval& rhs) 78 { 79 struct timeval ret; 80 ret.tv_sec=lhs.tv_sec + rhs.tv_sec; 81 ret.tv_usec=lhs.tv_usec + rhs.tv_usec; 82 normalizeTV(ret); 83 return ret; 84 } 85 86 const struct timeval operator-(const struct timeval& lhs, const struct timeval& rhs) 87 { 88 struct timeval ret; 89 ret.tv_sec=lhs.tv_sec - rhs.tv_sec; 90 ret.tv_usec=lhs.tv_usec - rhs.tv_usec; 91 normalizeTV(ret); 92 return ret; 93 } 94 95 const struct timeval operator*(int fact, const struct timeval& rhs) 96 { 97 // cout<<"In: "<<rhs.tv_sec<<" + "<<rhs.tv_usec<<"\n"; 98 struct timeval ret; 99 if( (2000000000 / fact) < rhs.tv_usec) { 100 double d=1.0 * rhs.tv_usec * fact; 101 ret.tv_sec=fact * rhs.tv_sec; 102 ret.tv_sec+=(int) (d/1000000); 103 d/=1000000; 104 d-=(int)d; 105 106 ret.tv_usec=1000000*d; 107 normalizeTV(ret); 108 109 cout<<"out complex: "<<ret.tv_sec<<" + "<<ret.tv_usec<<"\n"; 110 111 return ret; 112 } 113 114 ret.tv_sec=rhs.tv_sec * fact; 115 ret.tv_usec=rhs.tv_usec * fact; 116 117 normalizeTV(ret); 118 // cout<<"out simple: "<<ret.tv_sec<<" + "<<ret.tv_usec<<"\n"; 119 return ret; 120 } 121 122 123 bool operator<(const struct timeval& lhs, const struct timeval& rhs) 124 { 125 return make_pair(lhs.tv_sec, lhs.tv_usec) < make_pair(rhs.tv_sec, rhs.tv_usec); 126 } 127 128 129 130 46 131 class DNSIDManager : public boost::noncopyable 47 132 { … … 63 148 } 64 149 else 65 throw runtime_error("out of ids!"); 150 throw runtime_error("out of ids!"); // XXX FIXME 66 151 } 67 152 … … 249 334 IPEndpoint remote; 250 335 336 int res=waitForData(s_socket->getHandle(), 0, 25000); 337 if(res < 0 || res==0) 338 return; 339 251 340 while(s_socket->recvFromAsync(packet, remote)) { 252 341 try { … … 286 375 } 287 376 } 377 288 378 } 289 379 catch(exception& e) … … 413 503 dh->id=htons(qd.d_assignedID); 414 504 505 #if 0 415 506 if(lastsent.tv_sec && (!(s_questions%25))) { 416 507 double seconds=pr.d_pheader.ts.tv_sec - lastsent.tv_sec; … … 440 531 441 532 // cout<<"sending!"<<endl; 533 #endif 442 534 s_socket->sendTo(string(pr.d_payload, pr.d_payload + pr.d_len), remote); 443 535 } … … 503 595 504 596 unsigned int once=0; 597 struct timeval mental_time; 598 mental_time.tv_sec=0; mental_time.tv_usec=0; 599 600 if(!pr.getUDPPacket()) 601 return 0; 602 505 603 for(;;) { 604 506 605 if(!((once++)%100)) 507 606 houseKeeping(); 508 607 509 if(!g_throttled) { 608 int count=0; 609 while(pr.d_pheader.ts < mental_time) { 510 610 if(!pr.getUDPPacket()) 511 break;611 goto out; 512 612 513 613 sendPacketFromPR(pr, remote); 514 } 515 else 516 usleep(1000); // move to 'swift poll' 614 count++; 615 } 616 617 // cout<<count<<"\n"; 618 619 mental_time=pr.d_pheader.ts; 620 struct timeval then, now; 621 gettimeofday(&then,0); 517 622 518 623 receiveFromReference(); 519 } 624 625 gettimeofday(&now, 0); 626 627 mental_time= mental_time + 2*(now-then); 628 } 629 out:; 520 630 } 521 631 catch(exception& e)