mirror of https://github.com/Icinga/icinga2.git
Keep track of whether sockets are connected.
This commit is contained in:
parent
d793853671
commit
dd26fd46f5
|
@ -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,8 +368,12 @@ void Socket::WriteThreadProc(void)
|
|||
return;
|
||||
}
|
||||
|
||||
if (FD_ISSET(fd, &writefds))
|
||||
if (FD_ISSET(fd, &writefds)) {
|
||||
if (!m_Connected)
|
||||
m_Connected = true;
|
||||
|
||||
HandleWritable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@ protected:
|
|||
|
||||
private:
|
||||
SOCKET m_FD; /**< The socket descriptor. */
|
||||
bool m_Connected;
|
||||
|
||||
thread m_ReadThread;
|
||||
thread m_WriteThread;
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue