void* XDebugComThread::Entry() { clDEBUG() << "CodeLite >>> XDebugComThread started" << clEndl; //---------------------------------------------------------------- // Start the debugger server and wait for XDebug to connect to us //---------------------------------------------------------------- clSocketBase::Ptr_t client; int retry(0); try { wxString connectionString; connectionString << "tcp://" << m_host << ":" << m_port; clDEBUG() << "CodeLite >>> Creating server on:" << connectionString << clEndl; m_server.Start(connectionString); clDEBUG() << "CodeLite >>> Listening on" << m_host << ":" << m_port << clEndl; // Wait for new connection (up to m_waitForConnTimeout seconds, which defaults to 5 seconds ) do { if((m_waitForConnTimeout > 0) && (retry > m_waitForConnTimeout)) { // Don't wait any longer for XDebug m_xdebugMgr->CallAfter(&XDebugManager::XDebugNotConnecting); return NULL; } client = m_server.WaitForNewConnection(1); ++retry; clDEBUG() << "CodeLite >>> Waiting for connection.." << clEndl; } while(!TestDestroy() && !client); CL_DEBUG("CodeLite >>> Successfully accepted connection from XDebug!"); m_xdebugMgr->CallAfter(&XDebugManager::SetConnected, true); //---------------------------------------------------------------- // Protocol: // First we read the init XML //---------------------------------------------------------------- std::string initXML; if(DoReadReply(initXML, client)) { m_xdebugMgr->CallAfter(&XDebugManager::OnSocketInput, initXML); } else { // Something bad happened m_xdebugMgr->CallAfter(&XDebugManager::OnCommThreadTerminated); return NULL; } // The main loop: request-reply mode while(!TestDestroy()) { wxString command; if(m_queue.ReceiveTimeout(20, command) == wxMSGQUEUE_NO_ERROR) { DoSendCommand(command, client); // Wait for the reply std::string reply; if(!DoReadReply(reply, client)) { // AN error occurred - close session break; } // Notify XDebugManager m_xdebugMgr->CallAfter(&XDebugManager::OnSocketInput, reply); } } } catch(clSocketException& e) { CL_DEBUG("XDebugComThread caught an exception: %s", e.what()); m_xdebugMgr->CallAfter(&XDebugManager::OnCommThreadTerminated); return NULL; } m_xdebugMgr->CallAfter(&XDebugManager::OnCommThreadTerminated); return NULL; }
void* XDebugComThread::Entry() { wxLog::EnableLogging(false); CL_DEBUG("CodeLite >>> XDebugComThread started"); //---------------------------------------------------------------- // Start the debugger server and wait for XDebug to connect to us //---------------------------------------------------------------- clSocketBase::Ptr_t client; int retry(0); try { CL_DEBUG("CodeLite >>> Creating server on %s:%d", m_host, m_port); wxCharBuffer cb = m_host.mb_str(wxConvUTF8); m_server.CreateServer(cb.data(), m_port); CL_DEBUG("CodeLite >>> Listening on %s:%d", m_host, m_port); // Wait for new connection (up to 5 seconds ) do { if ( retry > 5 ) { // Don't wait any longer for XDebug m_xdebugMgr->CallAfter( &XDebugManager::XDebugNotConnecting ); return NULL; } client = m_server.WaitForNewConnection(1); ++retry; CL_DEBUG("CodeLite >>> waiting for connection.."); } while( !TestDestroy() && !client ); CL_DEBUG("CodeLite >>> Successfully accepted connection from XDebug!"); m_xdebugMgr->CallAfter( &XDebugManager::SetConnected, true ); //---------------------------------------------------------------- // Protocol: // First we read the init XML //---------------------------------------------------------------- std::string initXML; if ( DoReadReply( initXML, client ) ) { m_xdebugMgr->CallAfter( &XDebugManager::OnSocketInput, initXML ); } else { // Something bad happened m_xdebugMgr->CallAfter( &XDebugManager::OnCommThreadTerminated ); return NULL; } // The main loop: request-reply mode while ( !TestDestroy() ) { wxString command; if ( m_queue.ReceiveTimeout(20, command) == wxMSGQUEUE_NO_ERROR ) { DoSendCommand( command, client ); // Wait for the reply std::string reply; if ( !DoReadReply( reply, client ) ) { // AN error occurred - close session break; } // Notify XDebugManager m_xdebugMgr->CallAfter( &XDebugManager::OnSocketInput, reply ); } } } catch (clSocketException &e) { CL_DEBUG("XDebugComThread caught an exception: %s", e.what()); m_xdebugMgr->CallAfter( &XDebugManager::OnCommThreadTerminated ); return NULL; } m_xdebugMgr->CallAfter( &XDebugManager::OnCommThreadTerminated ); return NULL; }