Show
Ignore:
Timestamp:
04/29/06 23:49:33 (7 years ago)
Author:
ahu
Message:

Big bag of VC++ fixes, mostly by Michel 'Wimpie' Stol

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/pdns/pdns_recursor.cc

    r800 r802  
    1616    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    1717*/ 
     18 
     19#ifndef WIN32 
     20#include <netdb.h> 
     21#include <netinet/tcp.h> 
     22#include <unistd.h> 
     23#endif // WIN32 
    1824 
    1925#include "utility.hh"  
     
    2228#include <map> 
    2329#include <set> 
    24 #ifndef WIN32 
    25 #include <netdb.h> 
    26 #include <netinet/tcp.h> 
    27 #endif // WIN32 
    2830#include "recursor_cache.hh" 
    2931#include <stdio.h> 
    3032#include <signal.h> 
    3133#include <stdlib.h> 
    32 #include <unistd.h> 
    3334 
    3435#include "mtasker.hh" 
     
    182183int makeClientSocket(int family) 
    183184{ 
    184   int ret=socket(family, SOCK_DGRAM, 0); 
     185  int ret=(int)socket(family, SOCK_DGRAM, 0); 
    185186  if(ret < 0 && errno==EMFILE) // this is not a catastrophic error 
    186187    return ret; 
     
    316317      return -1;  
    317318 
    318     *d_len=packet.size(); 
     319    *d_len=(int)packet.size(); 
    319320    memcpy(data,packet.c_str(),min(len,*d_len)); 
    320321    if(*nearMissLimit && pident.nearMisses > *nearMissLimit) { 
     
    360361  ofstream of(fname.c_str()); 
    361362  if(of) 
    362     of<< getpid() <<endl; 
     363    of<< Utility::getpid() <<endl; 
    363364  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; 
    365366} 
    366367 
     
    427428  void closeAndCleanup() 
    428429  { 
    429     close(fd); 
     430    Utility::closesocket(fd); 
    430431    if(!g_tcpClientCounts[remote]--)  
    431432      g_tcpClientCounts.erase(remote); 
     
    535536      if(hadError) { 
    536537        g_fdm->removeReadFD(dc->d_socket); 
    537         close(dc->d_socket); 
     538  Utility::closesocket(dc->d_socket); 
    538539      } 
    539540      else { 
     
    589590  string sockname=::arg()["socket-dir"]+"/pdns_recursor.controlsocket"; 
    590591  if(::arg().mustDo("fork")) { 
    591     sockname+="."+lexical_cast<string>(getpid()); 
     592    sockname+="."+lexical_cast<string>(Utility::getpid()); 
    592593    L<<Logger::Warning<<"Forked control socket name: "<<sockname<<endl; 
    593594  } 
     
    677678  ComboAddress addr; 
    678679  socklen_t addrlen=sizeof(addr); 
    679   int newsock=accept(fd, (struct sockaddr*)&addr, &addrlen); 
     680  int newsock=(int)accept(fd, (struct sockaddr*)&addr, &addrlen); 
    680681  if(newsock>0) { 
    681682    g_stats.addRemote(addr); 
    682683    if(g_allowFrom && !g_allowFrom->match(&addr)) { 
    683684      g_stats.unauthorizedTCP++; 
    684       close(newsock); 
     685      Utility::closesocket(newsock); 
    685686      return; 
    686687    } 
     
    688689    if(g_maxTCPPerClient && g_tcpClientCounts.count(addr) && g_tcpClientCounts[addr] >= g_maxTCPPerClient) { 
    689690      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! 
    691692      return; 
    692693    } 
     
    955956  throw; 
    956957} 
    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; 
    1003959 
    1004960string questionExpand(const char* packet, uint16_t len) 
     
    1040996  shared_array<char> buffer(new char[pident->inNeeded]); 
    1041997 
    1042   int ret=read(fd, buffer.get(), pident->inNeeded); 
     998  int ret=recv(fd, buffer.get(), pident->inNeeded,0); 
    1043999  if(ret > 0) { 
    10441000    pident->inMSG.append(&buffer[0], &buffer[ret]); 
     
    10681024  PacketID* pid=any_cast<PacketID>(&var); 
    10691025   
    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); 
    10711027  if(ret > 0) { 
    10721028    pid->outPos+=ret; 
     
    11311087      for(MT_t::waiters_t::iterator mthread=MT->d_waiters.begin(); mthread!=MT->d_waiters.end(); ++mthread) { 
    11321088        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())) { 
    11341090          mthread->key.nearMisses++; 
    11351091        } 
     
    14031359    L<<", gcc "__VERSION__; 
    14041360#endif // add other compilers here 
     1361#ifdef _MSC_VER 
     1362        L<<", MSVC "<<_MSC_VER; 
     1363#endif 
    14051364    L<<") starting up"<<endl; 
    14061365 
     
    14521411 
    14531412    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)); 
    14551415    g_logCommonErrors=::arg().mustDo("log-common-errors"); 
    14561416