From 6a6976f866721cb381f3a5da762b73cd90a4468f Mon Sep 17 00:00:00 2001 From: Bert Hubert Date: Wed, 3 Oct 2012 19:15:45 +0000 Subject: [PATCH] removed use of select(2) from the webserver, to prepare us for fd>1024 use git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2739 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- pdns/session.cc | 137 ++++-------------------------------------------- 1 file changed, 9 insertions(+), 128 deletions(-) diff --git a/pdns/session.cc b/pdns/session.cc index af4380035..6fb9d2569 100644 --- a/pdns/session.cc +++ b/pdns/session.cc @@ -1,6 +1,6 @@ /* PowerDNS Versatile Database Driven Nameserver - Copyright (C) 2002 PowerDNS.COM BV + Copyright (C) 2002 - 2012 PowerDNS.COM BV This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 @@ -88,94 +88,12 @@ Session::Session(const Session &s) memcpy(rdbuf,s.rdbuf,d_bufsize); } -Session::Session(const string &dest, int port, int timeout) -{ - struct hostent *h; - h=gethostbyname(dest.c_str()); - if(!h) - throw SessionException("Unable to resolve target name"); - - if(timeout) - d_timeout=timeout; - - doConnect(*(int*)h->h_addr, port); -} - -Session::Session(uint32_t ip, int port, int timeout) -{ - if(timeout) - d_timeout=timeout; - - doConnect(ip, port); -} - void Session::setTimeout(unsigned int seconds) { d_timeout=seconds; } -void Session::doConnect(uint32_t ip, int port) -{ - init(); - clisock=socket(AF_INET,SOCK_STREAM,0); - Utility::setCloseOnExec(clisock); - - memset(&remote,0,sizeof(remote)); - remote.sin_family=AF_INET; - remote.sin_port=htons(port); - - remote.sin_addr.s_addr=ip; - - Utility::setNonBlocking( clisock ); - - int err; -#ifndef WIN32 - if((err=connect(clisock,(struct sockaddr*)&remote,sizeof(remote)))<0 && errno!=EINPROGRESS) { -#else - if((err=connect(clisock,(struct sockaddr*)&remote,sizeof(remote)))<0 && WSAGetLastError() != WSAEWOULDBLOCK ) { -#endif // WIN32 - throw SessionException("connect: "+stringerror()); - } - - if(!err) - goto done; - - fd_set rset,wset; - struct timeval tval; - - FD_ZERO(&rset); - FD_SET(clisock, &rset); - wset=rset; - tval.tv_sec=d_timeout; - tval.tv_usec=0; - - if(!select(clisock+1,&rset,&wset,0,tval.tv_sec ? &tval : 0)) - { - Utility::closesocket(clisock); // timeout - clisock=-1; - errno=ETIMEDOUT; - - throw SessionTimeoutException("Timeout connecting to server"); - } - - if(FD_ISSET(clisock, &rset) || FD_ISSET(clisock, &wset)) - { - Utility::socklen_t len=sizeof(err); - if(getsockopt(clisock, SOL_SOCKET,SO_ERROR,(char *)&err,&len)<0) - throw SessionException("Error connecting: "+stringerror()); // Solaris - - if(err) - throw SessionException("Error connecting: "+string(strerror(err))); - - } - else - throw SessionException("nonblocking connect failed"); - - done: - Utility::setBlocking( clisock ); -} - bool Session::putLine(const string &s) { int length=s.length(); @@ -184,29 +102,11 @@ bool Session::putLine(const string &s) while(written