diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-05-24 04:05:14 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-05-24 04:05:14 +0000 |
commit | 88a4177e285d65affeb2c2b97e308449a2c0cd4c (patch) | |
tree | 42361db8c02d39f2d9d495da590a28fd00c4e03a /src/connection.cpp | |
parent | 66f0cd6469d2643858c2fcd14726d362696bd68d (diff) |
Nonblocking connect() for outbound server links (why was this blocking anyway)
Changed /map to show authenticating servers with a * similar to hybrid
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1485 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/connection.cpp')
-rw-r--r-- | src/connection.cpp | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/src/connection.cpp b/src/connection.cpp index 9fb5070dd..31080615d 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -194,11 +194,14 @@ bool ircd_connector::CheckPing() } else { - this->SetWriteError("Ping timeout"); - this->CloseConnection(); - this->SetState(STATE_DISCONNECTED); - WriteOpers("*** Ping timeout on link to %s (more routes may remain)",this->GetServerName().c_str()); - return false; + if (this->GetState() == STATE_CONNECTED) + { + this->SetWriteError("Ping timeout"); + this->CloseConnection(); + this->SetState(STATE_DISCONNECTED); + WriteOpers("*** Ping timeout on link to %s (more routes may remain)",this->GetServerName().c_str()); + return false; + } } } } @@ -214,6 +217,18 @@ void ircd_connector::ResetPing() bool ircd_connector::FlushWriteBuf() { log(DEBUG,"connector::FlushWriteBuf()"); + if (this->GetState() == STATE_NOAUTH_OUTBOUND) + { + // if the outbound socket hasnt connected yet... return true and don't + // actually do anything until it IS connected. This should probably + // have a timeout somewhere, 10 secs should suffice. ;-) + pollfd polls; + polls.fd = this->fd; + polls.events = POLLOUT; + int ret = poll(&polls,1,1); + if (ret < 1) + return true; + } if (sendq.length()) { char* tb = (char*)this->sendq.c_str(); @@ -269,14 +284,17 @@ bool ircd_connector::MakeOutboundConnection(char* newhost, int newport) this->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (this->fd >= 0) { - if(connect(this->fd, (sockaddr*)&this->addr,sizeof(this->addr))) - { - WriteOpers("connect() failed for %s",host); - RemoveServer(this->servername.c_str()); - return false; - } int flags = fcntl(this->fd, F_GETFL, 0); fcntl(this->fd, F_SETFL, flags | O_NONBLOCK); + if(connect(this->fd, (sockaddr*)&this->addr,sizeof(this->addr)) == -1) + { + if (errno != EINPROGRESS) + { + WriteOpers("connect() failed for %s",host); + RemoveServer(this->servername.c_str()); + return false; + } + } int sendbuf = 32768; int recvbuf = 32768; setsockopt(this->fd,SOL_SOCKET,SO_SNDBUF,(const void *)&sendbuf,sizeof(sendbuf)); |