Changeset 802 for trunk/pdns/pdns/pdns_recursor.cc
- Timestamp:
- 04/29/06 23:49:33 (7 years ago)
- Files:
-
- 1 modified
-
trunk/pdns/pdns/pdns_recursor.cc (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pdns/pdns/pdns_recursor.cc
r800 r802 16 16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 17 */ 18 19 #ifndef WIN32 20 #include <netdb.h> 21 #include <netinet/tcp.h> 22 #include <unistd.h> 23 #endif // WIN32 18 24 19 25 #include "utility.hh" … … 22 28 #include <map> 23 29 #include <set> 24 #ifndef WIN3225 #include <netdb.h>26 #include <netinet/tcp.h>27 #endif // WIN3228 30 #include "recursor_cache.hh" 29 31 #include <stdio.h> 30 32 #include <signal.h> 31 33 #include <stdlib.h> 32 #include <unistd.h>33 34 34 35 #include "mtasker.hh" … … 182 183 int makeClientSocket(int family) 183 184 { 184 int ret= socket(family, SOCK_DGRAM, 0);185 int ret=(int)socket(family, SOCK_DGRAM, 0); 185 186 if(ret < 0 && errno==EMFILE) // this is not a catastrophic error 186 187 return ret; … … 316 317 return -1; 317 318 318 *d_len= packet.size();319 *d_len=(int)packet.size(); 319 320 memcpy(data,packet.c_str(),min(len,*d_len)); 320 321 if(*nearMissLimit && pident.nearMisses > *nearMissLimit) { … … 360 361 ofstream of(fname.c_str()); 361 362 if(of) 362 of<< getpid() <<endl;363 of<< Utility::getpid() <<endl; 363 364 else 364 L<<Logger::Error<<"Requested to write pid for "<< getpid()<<" to "<<fname<<" failed: "<<strerror(errno)<<endl;365 L<<Logger::Error<<"Requested to write pid for "<<Utility::getpid()<<" to "<<fname<<" failed: "<<strerror(errno)<<endl; 365 366 } 366 367 … … 427 428 void closeAndCleanup() 428 429 { 429 close(fd);430 Utility::closesocket(fd); 430 431 if(!g_tcpClientCounts[remote]--) 431 432 g_tcpClientCounts.erase(remote); … … 535 536 if(hadError) { 536 537 g_fdm->removeReadFD(dc->d_socket); 537 close(dc->d_socket);538 Utility::closesocket(dc->d_socket); 538 539 } 539 540 else { … … 589 590 string sockname=::arg()["socket-dir"]+"/pdns_recursor.controlsocket"; 590 591 if(::arg().mustDo("fork")) { 591 sockname+="."+lexical_cast<string>( getpid());592 sockname+="."+lexical_cast<string>(Utility::getpid()); 592 593 L<<Logger::Warning<<"Forked control socket name: "<<sockname<<endl; 593 594 } … … 677 678 ComboAddress addr; 678 679 socklen_t addrlen=sizeof(addr); 679 int newsock= accept(fd, (struct sockaddr*)&addr, &addrlen);680 int newsock=(int)accept(fd, (struct sockaddr*)&addr, &addrlen); 680 681 if(newsock>0) { 681 682 g_stats.addRemote(addr); 682 683 if(g_allowFrom && !g_allowFrom->match(&addr)) { 683 684 g_stats.unauthorizedTCP++; 684 close(newsock);685 Utility::closesocket(newsock); 685 686 return; 686 687 } … … 688 689 if(g_maxTCPPerClient && g_tcpClientCounts.count(addr) && g_tcpClientCounts[addr] >= g_maxTCPPerClient) { 689 690 g_stats.tcpClientOverflow++; 690 close(newsock); // don't call TCPConnection::closeAndCleanup here - did not enter it in the counts yet!691 Utility::closesocket(newsock); // don't call TCPConnection::closeAndCleanup here - did not enter it in the counts yet! 691 692 return; 692 693 } … … 955 956 throw; 956 957 } 957 958 959 #if 0 960 #include <execinfo.h> 961 962 multimap<uint32_t,string> rev; 963 for(map<string,uint32_t>::const_iterator i=casesptr->begin(); i!=casesptr->end(); ++i) { 964 rev.insert(make_pair(i->second,i->first)); 965 } 966 for(multimap<uint32_t,string>::const_iterator i=rev.begin(); i!= rev.end(); ++i) 967 cout<<i->first<<" times: \n"<<i->second<<"\n"; 968 969 cout.flush(); 970 971 map<string,uint32_t>* casesptr; 972 static string maketrace() 973 { 974 void *array[20]; //only care about last 17 functions (3 taken with tracing support) 975 size_t size; 976 char **strings; 977 size_t i; 978 979 size = backtrace (array, 5); 980 strings = backtrace_symbols (array, size); //Need -rdynamic gcc (linker) flag for this to work 981 982 string ret; 983 984 for (i = 0; i < size; i++) //skip useless functions 985 ret+=string(strings[i])+"\n"; 986 return ret; 987 } 988 989 extern "C" { 990 991 int gettimeofday (struct timeval *__restrict __tv, 992 __timezone_ptr_t __tz) 993 { 994 static map<string, uint32_t> s_cases; 995 casesptr=&s_cases; 996 s_cases[maketrace()]++; 997 __tv->tv_sec=time(0); 998 return 0; 999 } 1000 1001 } 1002 #endif 958 ; 1003 959 1004 960 string questionExpand(const char* packet, uint16_t len) … … 1040 996 shared_array<char> buffer(new char[pident->inNeeded]); 1041 997 1042 int ret=re ad(fd, buffer.get(), pident->inNeeded);998 int ret=recv(fd, buffer.get(), pident->inNeeded,0); 1043 999 if(ret > 0) { 1044 1000 pident->inMSG.append(&buffer[0], &buffer[ret]); … … 1068 1024 PacketID* pid=any_cast<PacketID>(&var); 1069 1025 1070 int ret= write(fd, pid->outMSG.c_str(), pid->outMSG.size() - pid->outPos);1026 int ret=send(fd, pid->outMSG.c_str(), pid->outMSG.size() - pid->outPos,0); 1071 1027 if(ret > 0) { 1072 1028 pid->outPos+=ret; … … 1131 1087 for(MT_t::waiters_t::iterator mthread=MT->d_waiters.begin(); mthread!=MT->d_waiters.end(); ++mthread) { 1132 1088 if(pident.fd==mthread->key.fd && mthread->key.remote==pident.remote && 1133 !strcasecmp(pident.domain.c_str(), mthread->key.domain.c_str())) {1089 !Utility::strcasecmp(pident.domain.c_str(), mthread->key.domain.c_str())) { 1134 1090 mthread->key.nearMisses++; 1135 1091 } … … 1403 1359 L<<", gcc "__VERSION__; 1404 1360 #endif // add other compilers here 1361 #ifdef _MSC_VER 1362 L<<", MSVC "<<_MSC_VER; 1363 #endif 1405 1364 L<<") starting up"<<endl; 1406 1365 … … 1452 1411 1453 1412 g_stats.remotes.resize(::arg().asNum("remotes-ringbuffer-entries")); 1454 memset(&*g_stats.remotes.begin(), 0, g_stats.remotes.size() * sizeof(RecursorStats::remotes_t::value_type)); 1413 if(!g_stats.remotes.empty()) 1414 memset(&g_stats.remotes[0], 0, g_stats.remotes.size() * sizeof(RecursorStats::remotes_t::value_type)); 1455 1415 g_logCommonErrors=::arg().mustDo("log-common-errors"); 1456 1416