Keep track of whether sockets are connected.

This commit is contained in:
Gunnar Beutner 2012-07-16 11:15:20 +02:00
parent d793853671
commit dd26fd46f5
3 changed files with 17 additions and 12 deletions

View File

@ -25,9 +25,8 @@ using namespace icinga;
* Constructor for the Socket class. * Constructor for the Socket class.
*/ */
Socket::Socket(void) Socket::Socket(void)
{ : m_FD(INVALID_SOCKET), m_Connected(false)
m_FD = INVALID_SOCKET; { }
}
/** /**
* Destructor for the Socket class. * Destructor for the Socket class.
@ -317,8 +316,12 @@ void Socket::ReadThreadProc(void)
return; return;
} }
if (FD_ISSET(fd, &readfds)) if (FD_ISSET(fd, &readfds)) {
if (!m_Connected)
m_Connected = true;
HandleReadable(); HandleReadable();
}
if (FD_ISSET(fd, &exceptfds)) if (FD_ISSET(fd, &exceptfds))
HandleException(); HandleException();
@ -337,7 +340,7 @@ void Socket::WriteThreadProc(void)
FD_ZERO(&writefds); FD_ZERO(&writefds);
while (!WantsToWrite()) { while (!WantsToWrite() && m_Connected) {
m_WriteCV.timed_wait(lock, boost::posix_time::seconds(1)); m_WriteCV.timed_wait(lock, boost::posix_time::seconds(1));
if (GetFD() == INVALID_SOCKET) if (GetFD() == INVALID_SOCKET)
@ -365,8 +368,12 @@ void Socket::WriteThreadProc(void)
return; return;
} }
if (FD_ISSET(fd, &writefds)) if (FD_ISSET(fd, &writefds)) {
if (!m_Connected)
m_Connected = true;
HandleWritable(); HandleWritable();
}
} }
} }

View File

@ -70,6 +70,7 @@ protected:
private: private:
SOCKET m_FD; /**< The socket descriptor. */ SOCKET m_FD; /**< The socket descriptor. */
bool m_Connected;
thread m_ReadThread; thread m_ReadThread;
thread m_WriteThread; thread m_WriteThread;

View File

@ -27,12 +27,9 @@ using namespace icinga;
* @param role The role of the TCP client socket. * @param role The role of the TCP client socket.
*/ */
TcpClient::TcpClient(TcpClientRole role) TcpClient::TcpClient(TcpClientRole role)
{ : m_Role(role), m_SendQueue(boost::make_shared<FIFO>()),
m_Role = role; m_RecvQueue(boost::make_shared<FIFO>())
{ }
m_SendQueue = boost::make_shared<FIFO>();
m_RecvQueue = boost::make_shared<FIFO>();
}
/** /**
* Retrieves the role of the socket. * Retrieves the role of the socket.