]> git.saurik.com Git - apt.git/blobdiff - methods/connect.cc
* removed dead code
[apt.git] / methods / connect.cc
index d1d71b00445c74db0825f1c6dfe99157373350c4..145001fb37c2aa637cfaecca46b944a0acc2b001 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: connect.cc,v 1.11 2004/01/07 20:39:38 mdz Exp $
+// $Id: connect.cc,v 1.10.2.1 2004/01/16 18:58:50 mdz Exp $
 /* ######################################################################
 
    Connect - Replacement connect call
@@ -18,6 +18,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include <unistd.h>
+#include <sstream>
 
 // Internet stuff
 #include <netinet/in.h>
@@ -67,12 +68,10 @@ static bool DoConnect(struct addrinfo *Addr,string Host,
       wrong this will get tacked onto the end of the error message */
    if (LastHostAddr->ai_next != 0)
    {
-      char Name2[NI_MAXHOST + NI_MAXSERV + 10];
-      snprintf(Name2,sizeof(Name2),_("[IP: %s %s]"),Name,Service);
-      Owner->SetFailExtraMsg(string(Name2));
-   }   
-   else
-      Owner->SetFailExtraMsg("");
+      std::stringstream ss;
+      ioprintf(ss, _("[IP: %s %s]"),Name,Service);
+      Owner->SetIP(ss.str());
+   }
       
    // Get a socket
    if ((Fd = socket(Addr->ai_family,Addr->ai_socktype,
@@ -88,9 +87,11 @@ static bool DoConnect(struct addrinfo *Addr,string Host,
    
    /* This implements a timeout for connect by opening the connection
       nonblocking */
-   if (WaitFd(Fd,true,TimeOut) == false)
+   if (WaitFd(Fd,true,TimeOut) == false) {
+      Owner->SetFailReason("Timeout");
       return _error->Error(_("Could not connect to %s:%s (%s), "
                           "connection timed out"),Host.c_str(),Service,Name);
+   }
 
    // Check the socket for an error condition
    unsigned int Err;
@@ -101,6 +102,8 @@ static bool DoConnect(struct addrinfo *Addr,string Host,
    if (Err != 0)
    {
       errno = Err;
+      if(errno == ECONNREFUSED)
+         Owner->SetFailReason("ConnectionRefused");
       return _error->Errno("connect",_("Could not connect to %s:%s (%s)."),Host.c_str(),
                           Service,Name);
    }
@@ -160,12 +163,16 @@ bool Connect(string Host,int Port,const char *Service,int DefPort,int &Fd,
                  DefPort = 0;
                  continue;
               }
+              Owner->SetFailReason("ResolveFailure");
               return _error->Error(_("Could not resolve '%s'"),Host.c_str());
            }
            
            if (Res == EAI_AGAIN)
+           {
+              Owner->SetFailReason("TmpResolveFailure");
               return _error->Error(_("Temporary failure resolving '%s'"),
                                    Host.c_str());
+           }
            return _error->Error(_("Something wicked happened resolving '%s:%s' (%i)"),
                                 Host.c_str(),ServStr,Res);
         }