unsigned long TelnetSession::InnerOutputThread() { unsigned char* receivedData = NULL; // Main program loop while(activeConnection) { try { // Download data receivedData = (unsigned char*)connection->receive(); } catch(char* errorMessage) { // Connection has been dropped activeConnection = false; KillThreads(); return 0; } // Scan for command codes unsigned char *pPos = receivedData; while(*pPos != '\0') { // Telnet control code if(*pPos == IAC) { int bytesRead = handleCommand(pPos); pPos += bytesRead; } // VT100 control code else if(*pPos == VT_ESC) { int bytesRead = handleVTCommand(pPos); pPos += bytesRead; } // Just text else { if (NULL != console) { cout << *pPos; cout.flush(); } WaitForSingleObject(m_hMtxS2CBuf, INFINITE); m_s2cBuf += *pPos; ReleaseMutex(m_hMtxS2CBuf); pPos++; } } delete[] receivedData; } KillThreads(); return 0; }
// Default destructor TelnetSession::~TelnetSession() { WSACleanup(); if(NULL != console) delete console; KillThreads(); if (NULL != m_hMtxS2CBuf) { CloseHandle(m_hMtxS2CBuf); m_hMtxS2CBuf = NULL; } }
void ToastEngine::run() { g_config = new (std::nothrow)toast::SystemConfig; LoadConfig(Daemon::Instance()->config); int lastTime = time(NULL); // initlize global varables Initlize(); // Create agent response thread; g_agent_response_threads = MultiWorkQueueThreadPool::Create(g_config->num_response_process_threads, NULL); CreateFunctionalThreads(); Log::Debug("All the thread created " ); while(false==Daemon::Instance()->IsStop()) { int now = time(NULL); usleep(1000000); } KillThreads(m_OtherThreadPool); }
void EventDlg_OnCommand(HWND hDlg, int id, HWND hwndCtl, UINT codeNotify) { int rc; switch (id) { case IDC_AUTOMATIC: KillThreads(); if (hEventObject) rc = CloseHandle(hEventObject); MTVERIFY( hEventObject = CreateEvent(NULL, // Security FALSE, // Automatic (FALSE = not manual) 0, // Clear on creation "EventTest")// Name of object ); // CreateEvent ALWAYS sets the last error if (GetLastError() == ERROR_ALREADY_EXISTS) AddToList("WARNING: Event wasn't destroyed"); StartThreads(); AddToList("Event set to AUTOMATIC"); break; case IDC_MANUAL: KillThreads(); if (hEventObject) rc = CloseHandle(hEventObject); MTVERIFY( hEventObject = CreateEvent(NULL, // Security TRUE, // Manual 0, // Clear on creation "EventTest")// Name of object ); if (GetLastError() == ERROR_ALREADY_EXISTS) AddToList("Reusing old event"); StartThreads(); AddToList("Event set to MANUAL"); break; case IDC_SIGNAL: MTVERIFY( SetEvent(hEventObject) ); break; case IDC_RESET: MTVERIFY( ResetEvent(hEventObject) ); break; case IDC_PULSE: MTVERIFY( PulseEvent(hEventObject) ); break; case IDC_CLEAR: ListBox_ResetContent(GetDlgItem(hDlg, IDC_RESULTS)); break; case IDCANCEL: case IDM_EXIT: PostMessage(GetParent(hDlg),WM_DESTROY, (WPARAM)0, (LPARAM)0); DestroyWindow(hDlgMain); hDlgMain = NULL; break; default: break; } }