Changeset 436 for trunk/pdns/pdns/pdns_recursor.cc
- Timestamp:
- 07/10/05 14:23:15 (8 years ago)
- Files:
-
- 1 modified
-
trunk/pdns/pdns/pdns_recursor.cc (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pdns/pdns/pdns_recursor.cc
r435 r436 79 79 static int d_clientsock; 80 80 static vector<int> d_udpserversocks; 81 static vector<int> d_tcpserversocks; 82 81 82 typedef vector<int> tcpserversocks_t; 83 static tcpserversocks_t s_tcpserversocks; 83 84 84 85 struct PacketID … … 352 353 Utility::setNonBlocking(fd); 353 354 listen(fd, 128); 354 d_tcpserversocks.push_back(fd);355 s_tcpserversocks.push_back(fd); 355 356 L<<Logger::Error<<"Listening for TCP queries on "<<inet_ntoa(sin.sin_addr)<<":"<<arg().asNum("local-port")<<endl; 356 357 } … … 469 470 struct sockaddr_in remote; 470 471 char data[65535]; 472 time_t startTime; 471 473 }; 472 474 … … 497 499 arg().set("delegation-only","Which domains we only accept delegations from")=""; 498 500 arg().set("query-local-address","Source IP address for sending queries")="0.0.0.0"; 501 arg().set("client-tcp-timeout","Timeout in seconds when talking to TCP clients")="2"; 502 arg().set("max-tcp-clients","Maximum number of simultaneous TCP clients")="128"; 499 503 500 504 arg().setCmd("help","Provide a helpful message"); … … 575 579 vector<TCPConnection> tcpconnections; 576 580 counter=0; 581 time_t now; 582 unsigned int maxTcpClients=arg().asNum("max-tcp-clients"); 577 583 for(;;) { 578 584 while(MT->schedule()); // housekeeping, let threads do their thing … … 597 603 int fdmax=d_clientsock; 598 604 599 for(vector<TCPConnection>::const_iterator i=tcpconnections.begin();i!=tcpconnections.end();++i) { 600 FD_SET(i->fd, &readfds); 601 fdmax=max(fdmax,i->fd); 602 } 605 if(!tcpconnections.empty()) 606 now=time(0); 607 608 vector<TCPConnection> sweeped; 609 int tcpLimit=arg().asNum("client-tcp-timeout"); 610 for(vector<TCPConnection>::iterator i=tcpconnections.begin();i!=tcpconnections.end();++i) { 611 if(now < i->startTime + tcpLimit) { 612 FD_SET(i->fd, &readfds); 613 fdmax=max(fdmax,i->fd); 614 sweeped.push_back(*i); 615 } 616 else { 617 L<<Logger::Error<<"TCP timeout from client "<<inet_ntoa(i->remote.sin_addr)<<endl; 618 close(i->fd); 619 } 620 } 621 sweeped.swap(tcpconnections); 622 603 623 for(vector<int>::const_iterator i=d_udpserversocks.begin(); i!=d_udpserversocks.end(); ++i) { 604 624 FD_SET( *i, &readfds ); 605 625 fdmax=max(fdmax,*i); 606 626 } 607 for(vector<int>::const_iterator i=d_tcpserversocks.begin(); i!=d_tcpserversocks.end(); ++i) { 608 FD_SET( *i, &readfds ); 609 fdmax=max(fdmax,*i); 610 } 627 if(tcpconnections.size() < maxTcpClients) 628 for(tcpserversocks_t::const_iterator i=s_tcpserversocks.begin(); i!=s_tcpserversocks.end(); ++i) { 629 FD_SET(*i, &readfds ); 630 fdmax=max(fdmax,*i); 631 } 632 611 633 for(map<int,PacketID>::const_iterator i=d_tcpclientreadsocks.begin(); i!=d_tcpclientreadsocks.end(); ++i) { 612 634 // cerr<<"Adding TCP socket "<<i->first<<" to read select set"<<endl; … … 672 694 } 673 695 674 for( vector<int>::const_iterator i=d_tcpserversocks.begin(); i!=d_tcpserversocks.end(); ++i) {696 for(tcpserversocks_t::const_iterator i=s_tcpserversocks.begin(); i!=s_tcpserversocks.end(); ++i) { 675 697 if(FD_ISSET(*i ,&readfds)) { // do we have a new TCP connection 676 698 struct sockaddr_in addr; … … 684 706 tc.state=TCPConnection::BYTE0; 685 707 tc.remote=addr; 708 tc.startTime=time(0); 686 709 tcpconnections.push_back(tc); 687 710 }