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.
*/
Socket::Socket(void)
{
m_FD = INVALID_SOCKET;
}
: m_FD(INVALID_SOCKET), m_Connected(false)
{ }
/**
* Destructor for the Socket class.
@ -317,8 +316,12 @@ void Socket::ReadThreadProc(void)
return;
}
if (FD_ISSET(fd, &readfds))
if (FD_ISSET(fd, &readfds)) {
if (!m_Connected)
m_Connected = true;
HandleReadable();
}
if (FD_ISSET(fd, &exceptfds))
HandleException();
@ -337,7 +340,7 @@ void Socket::WriteThreadProc(void)
FD_ZERO(&writefds);
while (!WantsToWrite()) {
while (!WantsToWrite() && m_Connected) {
m_WriteCV.timed_wait(lock, boost::posix_time::seconds(1));
if (GetFD() == INVALID_SOCKET)
@ -365,10 +368,14 @@ void Socket::WriteThreadProc(void)
return;
}
if (FD_ISSET(fd, &writefds))
if (FD_ISSET(fd, &writefds)) {
if (!m_Connected)
m_Connected = true;
HandleWritable();
}
}
}
mutex& Socket::GetMutex(void) const
{

View File

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

View File

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