]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspsocket.cpp
/who tidyup - needs QA'ing
[user/henk/code/inspircd.git] / src / inspsocket.cpp
index c311a78faa59e713c4f22adf5d726869361e6d24..b9d31845fb33d958fc86ab7b53e019c51d1513a5 100644 (file)
@@ -18,8 +18,6 @@
 #include "inspircd.h"
 
 using irc::sockets::OpenTCPSocket;
-using irc::sockets::insp_inaddr;
-using irc::sockets::insp_sockaddr;
 
 bool InspSocket::Readable()
 {
@@ -131,7 +129,14 @@ InspSocket::InspSocket(InspIRCd* SI, const std::string &ipaddr, int aport, bool
                {
                        strlcpy(this->IP,host,MAXBUF);
                        timeout_val = maxtime;
-                       this->DoConnect();
+                       if (!this->DoConnect())
+                       {
+                               this->Close();
+                               this->fd = -1;
+                               this->state = I_ERROR;
+                               this->OnError(I_ERR_CONNECT);
+                               return;
+                       }
                }
        }
 }
@@ -161,6 +166,7 @@ void InspSocket::SetQueues(int nfd)
  */
 bool InspSocket::BindAddr(const std::string &ip)
 {
+       Instance->Log(DEBUG,"BindAddr(%s)", ip.c_str());
        ConfigReader Conf(this->Instance);
        bool bindfail = false;
        socklen_t size = sizeof(sockaddr_in);
@@ -171,7 +177,7 @@ bool InspSocket::BindAddr(const std::string &ip)
                v6 = true;
 #endif
        int j = 0;
-       while ((j < Conf.Enumerate("bind")) && (!ip.empty()))
+       while (j < Conf.Enumerate("bind") || (!ip.empty()))
        {
                std::string IP = ip.empty() ? Conf.ReadValue("bind","address",j) : ip;
                if (!ip.empty() || Conf.ReadValue("bind","type",j) == "servers")
@@ -261,9 +267,25 @@ bool InspSocket::DoConnect()
        else
        {
                this->fd = socket(AF_INET, SOCK_STREAM, 0);
+               if (this->fd > -1)
+               {
+                       if (!this->BindAddr(this->cbindip))
+                       {
+                               delete[] addr;
+                               return false;
+                       }
+               }
        }
 #else
        this->fd = socket(AF_INET, SOCK_STREAM, 0);
+       if (this->fd > -1)
+       {
+               if (!this->BindAddr(this->cbindip))
+               {
+                       delete[] addr;
+                       return false;
+               }
+       }
 #endif
 
        if (this->fd == -1)