//--------------------------------------------------------------------------------
bool CSystemMonitorHandlerThread::MainLoop()
	{
	CReadLock lock(GetStatePtr());

	if(! IsThreadBusy())
		return CheckState();

	// m_pSocket wont be valid until MSG_NEWCONNECTION msg is received
	if(! m_socket.IsValid())
		{
		SetThreadBusy(false);
		return CheckState();
		}

#ifndef _DEBUG
	CTime ctCurrent(CTime::GetCurrentTime());
	if(m_ctLastActivity < ctCurrent - CTimeSpan(0, 0, 5, 0))
		{
		CString sTemp("----* Session timed out *----\r\n");
		m_socket.Send(sTemp, CSmallSocket::WAITFORWOULDBLOCK);
		SetThreadBusy(false);
		return CheckState();
		}
#endif

	CString sTemp;
	int nLen = 0;

	nLen = m_socket.Receive(sTemp.GetBuffer(1024), 1024, CSmallSocket::WAITFORDATA, 1000);

	// when there's no data (but no error) Receive will return len==-1 and err == WSAEWOULDBLOCK
	long nErr = ::WSAGetLastError();
	if(nLen < 1 && nErr != WSAEWOULDBLOCK)
		{
		::WSASetLastError(nErr);
		sTemp.ReleaseBuffer(0);
		SetThreadBusy(false);
		return CheckState();
		}

	if(nLen < 1)
		nLen = 0;

	sTemp.ReleaseBuffer(nLen);

	if(nLen > 0)
		{
#ifndef _DEBUG
		m_ctLastActivity = ctCurrent;
#endif

		int nIndex = sTemp.FindOneOf("\r\n");
		if(nIndex != -1)
			{
			sTemp.GetBufferSetLength(nIndex);
			sTemp.ReleaseBuffer(nIndex);
			m_sCurCmd += sTemp;
			if(! DoCommand())
				SetThreadBusy(false);
			}
		else
			if(sTemp.GetLength() > 0)
				m_sCurCmd += sTemp;
		}

	return CheckState();
	}
Esempio n. 2
0
void wxPropertyGridPage::Clear()
{
    GetStatePtr()->DoClear();
}