bool MagicFun3( HDC hSrcDC , int x , int y , HDC hDestDC , int xd , int yd , int width , int height , int nDelay, int nStep) { if( nStep < 1 )nStep = 1; for(int i=0;i<width; i+=nStep ) { BitBlt(hDestDC, xd+i,yd,nStep,height,hSrcDC,x+i,y,SRCCOPY); SleepEx(nDelay); } BitBlt( hDestDC , xd , yd , width , height ,hSrcDC,x,y,SRCCOPY); return TRUE; }
void SpectraVFSCached::WaitForIO( IOHandle &_handle ) { #ifdef SPECTRAVFS_ASYNC_IO // Timer t; while ( _handle.isSet() ) { SleepEx(1,true); } // float time = t.GetElapsedSecs(); // printf("%f sec\n", time ); #endif }
int limbosleep(ulong milsec) { if (sleepers > MAXSLEEPERS) return -1; sleepers++; up->syscall = SYS_SLEEP; SleepEx(milsec, TRUE); up->syscall = 0; sleepers--; return 0; }
EXPORT_SYM VOID CALLBACK My_APCProc(ULONG_PTR dwParam) { beenHere++; if(dwParam == 1) { return; } QueueUserAPC(My_APCProc, GetCurrentThread() , dwParam - 1); DWORD status = SleepEx(INFINITE , true); printf("SleepEx status = 0x%x \n" ,status); }
static void monitor_thread (gpointer unused) { ThreadPool *pools [2]; MonoInternalThread *thread; guint32 ms; gboolean need_one; int i; pools [0] = &async_tp; pools [1] = &async_io_tp; thread = mono_thread_internal_current (); ves_icall_System_Threading_Thread_SetName_internal (thread, mono_string_new (mono_domain_get (), "Threadpool monitor")); while (1) { ms = 500; do { guint32 ts; ts = mono_msec_ticks (); if (SleepEx (ms, TRUE) == 0) break; ms -= (mono_msec_ticks () - ts); if (mono_runtime_is_shutting_down ()) break; if (THREAD_WANTS_A_BREAK (thread)) mono_thread_interruption_checkpoint (); } while (ms > 0); if (mono_runtime_is_shutting_down ()) break; for (i = 0; i < 2; i++) { ThreadPool *tp; tp = pools [i]; if (tp->waiting > 0) continue; need_one = (mono_cq_count (tp->queue) > 0); if (!need_one && !tp->is_io) { EnterCriticalSection (&wsqs_lock); for (i = 0; wsqs != NULL && i < wsqs->len; i++) { MonoWSQ *wsq; wsq = g_ptr_array_index (wsqs, i); if (mono_wsq_count (wsq) != 0) { need_one = TRUE; break; } } LeaveCriticalSection (&wsqs_lock); } if (need_one) threadpool_start_thread (tp); } } }
static void gtaThreadProc(void*) { Netlib_Logf(NULL, "GTA thread start"); SHORTDATA data = { 0 }; while (!MirandaExiting()) { Sync(CLUI_SyncGetShortData, (WPARAM)pcli->hwndContactTree, (LPARAM)&data); while (true) { if (MirandaExiting()) goto LBL_Exit; SleepEx(0, TRUE); //1000 contacts per second GTACHAINITEM mpChain = { 0 }; SHORTDATA dat2 = { 0 }; if (!gtaGetItem(&mpChain)) break; SHORTDATA *dat; if (mpChain.dat == NULL || (!IsBadReadPtr(mpChain.dat, sizeof(*mpChain.dat)) && mpChain.dat->hWnd == data.hWnd)) dat = &data; else { Sync(CLUI_SyncGetShortData, (WPARAM)mpChain.dat->hWnd, (LPARAM)&dat2); dat = &dat2; } if (MirandaExiting()) goto LBL_Exit; ClcCacheEntry cacheEntry; memset(&cacheEntry, 0, sizeof(cacheEntry)); cacheEntry.hContact = mpChain.hContact; if (!Sync(CLUI_SyncGetPDNCE, (WPARAM)0, (LPARAM)&cacheEntry)) { Cache_GetSecondLineText(dat, &cacheEntry); Cache_GetThirdLineText(dat, &cacheEntry); Sync(CLUI_SyncSetPDNCE, (WPARAM)CCI_LINES, (LPARAM)&cacheEntry); CListSettings_FreeCacheItemData(&cacheEntry); } KillTimer(dat->hWnd, TIMERID_INVALIDATE_FULL); CLUI_SafeSetTimer(dat->hWnd, TIMERID_INVALIDATE_FULL, 500, NULL); } WaitForSingleObjectEx(hgtaWakeupEvent, INFINITE, TRUE); ResetEvent(hgtaWakeupEvent); } LBL_Exit: CloseHandle(hgtaWakeupEvent); hgtaWakeupEvent = NULL; g_hGetTextAsyncThread = NULL; Netlib_Logf(NULL, "GTA thread end"); }
int __cdecl main( int argc, char **argv ) { DWORD OldTickCount; DWORD NewTickCount; DWORD MaxDelta; DWORD TimeDelta; DWORD i; if (0 != (PAL_Initialize(argc, argv))) { return FAIL; } for (i = 0; i<sizeof(testCases) / sizeof(testCases[0]); i++) { OldTickCount = GetTickCount(); SleepEx(testCases[i].SleepTime, testCases[i].Alertable); NewTickCount = GetTickCount(); /* * Check for DWORD wraparound */ if (OldTickCount>NewTickCount) { OldTickCount -= NewTickCount+1; NewTickCount = 0xFFFFFFFF; } TimeDelta = NewTickCount - OldTickCount; /* For longer intervals use a 10 percent tolerance */ if ((testCases[i].SleepTime * 0.1) > AcceptableTimeError) { MaxDelta = testCases[i].SleepTime + (DWORD)(testCases[i].SleepTime * 0.1); } else { MaxDelta = testCases[i].SleepTime + AcceptableTimeError; } if (TimeDelta < testCases[i].SleepTime || TimeDelta > MaxDelta) { Fail("The sleep function slept for %d ms when it should have " "slept for %d ms\n", TimeDelta, testCases[i].SleepTime); } } PAL_Terminate(); return PASS; }
FileMon::~FileMon() { #ifdef WIN32 for(auto i : mWatches) { WatchStruct* pWatch=i.second; DWORD dwWaitResult = WaitForSingleObject(ghMutex,INFINITE); while(true) { if(dwWaitResult==WAIT_OBJECT_0) { pWatch->mStopNow = TRUE; if(!ReleaseMutex(ghMutex)) { std::cout << "FileMon : Release mutex err.\n"; } break; } else if(dwWaitResult==WAIT_ABANDONED) { break; } } CancelIo(pWatch->mDirHandle); ReadDirectoryChangesW( pWatch->mDirHandle,pWatch->mBuffer,sizeof(pWatch->mBuffer),FALSE, pWatch->mNotifyFilter,NULL,&pWatch->mOverlapped,0); if(!HasOverlappedIoCompleted(&pWatch->mOverlapped)) { SleepEx(5,TRUE); } CloseHandle(pWatch->mOverlapped.hEvent); CloseHandle(pWatch->mDirHandle); HeapFree(GetProcessHeap(),0,pWatch); } CloseHandle(ghMutex); #endif #ifdef LINUX if(notify) { for(auto i : watchMap) { inotify_rm_watch(notify,i.first); //unnecessary because of close below? } } if(notify) { close(notify); } #endif }
bool MagicFun10( HDC hSrcDC , int x , int y , HDC hDestDC , int xd , int yd , int width , int height , int nDelay, int nStep ) { if( nStep < 4 ) nStep = 4; int nXNum = width / nStep + 1 , nYNum = height / nStep + 1; int nLoop = 0; while( nLoop < nYNum/2 ) { for( int i = 0 ; i< nXNum-nLoop; i++ ) { BitBlt( hDestDC , xd+i*nStep , yd+nLoop*nStep , nStep , nStep , hSrcDC , x+i*nStep , y+nLoop*nStep , SRCCOPY ); SleepEx(nDelay); } for(int i = 0 ; i< nYNum-nLoop; i++ ) { BitBlt( hDestDC , xd+width-(nLoop+1)*nStep , yd+i*nStep , nStep , nStep , hSrcDC , x+width-(nLoop+1)*nStep , y+i*nStep , SRCCOPY ); SleepEx(nDelay); } for( int i = nXNum-nLoop ; i >=0 ; i-- ) { BitBlt( hDestDC , xd+(i-1)*nStep , yd+height-(nLoop+1)*nStep , nStep , nStep , hSrcDC , x+(i-1)*nStep ,y+height-(nLoop+1)*nStep , SRCCOPY ); SleepEx(nDelay); } for( int i = nYNum-nLoop ; i>=0 ; i-- ) { BitBlt( hDestDC , xd+nLoop*nStep , yd+(i-1)*nStep , nStep , nStep , hSrcDC , x+nLoop*nStep , y+(i-1)*nStep , SRCCOPY ); SleepEx(nDelay); } nLoop++; } BitBlt( hDestDC , xd , yd , width , height , hSrcDC , x , y , SRCCOPY ); return TRUE; }
void TwitterProto::MessageLoop(void*) { LOG("***** Entering Twitter::MessageLoop"); since_id_ = db_pod_get<twitter_id>(0,m_szModuleName,TWITTER_KEY_SINCEID,0); dm_since_id_ = db_pod_get<twitter_id>(0,m_szModuleName,TWITTER_KEY_DMSINCEID,0); bool new_account = db_byte_get(0,m_szModuleName,TWITTER_KEY_NEW,1) != 0; bool popups = db_byte_get(0,m_szModuleName,TWITTER_KEY_POPUP_SIGNON,1) != 0; int poll_rate = db_dword_get(0,m_szModuleName,TWITTER_KEY_POLLRATE,80); for(unsigned int i=0;;i++) { if(m_iStatus != ID_STATUS_ONLINE) goto exit; if(i%4 == 0) UpdateFriends(); if(m_iStatus != ID_STATUS_ONLINE) goto exit; UpdateStatuses(new_account,popups); if(m_iStatus != ID_STATUS_ONLINE) goto exit; UpdateMessages(new_account); if(new_account) // Not anymore! { new_account = false; DBWriteContactSettingByte(0,m_szModuleName,TWITTER_KEY_NEW,0); } if(m_iStatus != ID_STATUS_ONLINE) goto exit; LOG("***** TwitterProto::MessageLoop going to sleep..."); if(SleepEx(poll_rate*1000,true) == WAIT_IO_COMPLETION) goto exit; LOG("***** TwitterProto::MessageLoop waking up..."); popups = true; } exit: { ScopedLock s(twitter_lock_); twit_.set_credentials("","",false); } LOG("***** Exiting TwitterProto::MessageLoop"); }
// Directly ripped from Foundation.... static void __CFMilliSleep(uint32_t msecs) { #if TARGET_OS_WIN32 SleepEx(msecs, false); #elif defined(__svr4__) || defined(__hpux__) sleep((msecs + 900) / 1000); #elif TARGET_OS_OSX || TARGET_OS_LINUX struct timespec input; input.tv_sec = msecs / 1000; input.tv_nsec = (msecs - input.tv_sec * 1000) * 1000000; nanosleep(&input, NULL); #else #error Dont know how to define sleep for this platform #endif }
static BOOL CallBackAndWait(struct CpuUsageThreadParams *param,BYTE nCpuUsage) { if (param->hFirstEvent != NULL) { /* return value for PollCpuUsage() */ *param->pidThread=GetCurrentThreadId(); SetEvent(param->hFirstEvent); param->hFirstEvent=NULL; /* lower priority after first call */ SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_IDLE); } if (!param->pfnDataAvailProc(nCpuUsage,param->lParam)) return FALSE; SleepEx(param->dwDelayMillis,TRUE); return !Miranda_Terminated(); }
VOID PALAPI APCFunc(ULONG_PTR ulptrParam) { LONG lThreadIdx = (LONG)ulptrParam; executing_thread_info * peti = (executing_thread_info *)&g_rgEti[lThreadIdx]; LONG lVal; BOOL bAlertableSleep = (BOOL)(peti->lDepth < MAX_RECURSION_DEPTH); lVal = InterlockedDecrement(&g_rglOutstandingAPCs[lThreadIdx]); peti->lAPCCount++; peti->lDepth += 1; SleepEx(rand() % APC_FUNC_SLEEPTIME, bAlertableSleep); peti->lDepth -= 1; }
void PauseTheDownload(int rv, int *iFileDownloadRetries) { if(rv != nsFTPConn::E_USER_CANCEL) { SendMessage(dlgInfo.hWndDlg, WM_COMMAND, IDPAUSE, 0); --*iFileDownloadRetries; } while(gdwDownloadDialogStatus == CS_PAUSE) { SleepEx(200, FALSE); ProcessWindowsMessages(); } }
MMRESULT Midi_InClose(MIDI *midi) { MMRESULT error; int i; if (midi->inPort == -1) { return MMSYSERR_NOERROR; } m_closing = TRUE; error = midiInReset(midi->midiIn); if (error != MMSYSERR_NOERROR) { return error; } /* * Unprepare the pending midi buffer header. */ for (i = 0; i < midi->bufCnt; i++) { UnprepareHeader: error = midiInUnprepareHeader(midi->midiIn, &midi->midiHdrs[i] , sizeof(MIDIHDR)); if (error == MIDIERR_STILLPLAYING) { midiInReset(midi->midiIn); SleepEx(50, FALSE); goto UnprepareHeader; } } CloseMidi: error = midiInClose(midi->midiIn); if (error == MIDIERR_STILLPLAYING) { midiInReset(midi->midiIn); SleepEx(50, FALSE); goto CloseMidi; } midi->midiIn = NULL; return error; }
/***************************************************************************** * ReadComm (USER.204) */ INT16 WINAPI ReadComm16(INT16 cid,LPSTR lpvBuf,INT16 cbRead) { int status, length; struct DosDeviceStruct *ptr; LPSTR orgBuf = lpvBuf; TRACE("cid %d, ptr %p, length %d\n", cid, lpvBuf, cbRead); if ((ptr = GetDeviceStruct(cid)) == NULL) { FIXME("no handle for cid = %0x!\n",cid); return -1; } if (ptr->suspended) { ptr->commerror = IE_HARDWARE; return -1; } if(0==comm_inbuf(ptr)) SleepEx(1,TRUE); /* read unget character */ if (ptr->unget>=0) { *lpvBuf++ = ptr->unget; ptr->unget = -1; length = 1; } else length = 0; /* read from receive buffer */ while (length < cbRead) { status = ((ptr->ibuf_head < ptr->ibuf_tail) ? ptr->ibuf_size : ptr->ibuf_head) - ptr->ibuf_tail; if (!status) break; if ((cbRead - length) < status) status = cbRead - length; memcpy(lpvBuf, ptr->inbuf + ptr->ibuf_tail, status); ptr->ibuf_tail += status; if (ptr->ibuf_tail >= ptr->ibuf_size) ptr->ibuf_tail = 0; lpvBuf += status; length += status; } TRACE("%s\n", debugstr_an( orgBuf, length )); ptr->commerror = 0; return length; }
/* Entry Point for child thread. All it does is call SleepEx. */ DWORD PALAPI SleeperProc(LPVOID lpParameter) { DWORD ret; /* signal the main thread that we're ready to proceed */ if( ! SetEvent( hSyncEvent1 ) ) { Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); bThreadResult = FAIL; goto done; } /* wait for notification from the main thread */ ret = WaitForSingleObject( hSyncEvent2, 20000 ); if( ret != WAIT_OBJECT_0 ) { Trace( "ERROR:WaitForSingleObject() returned %lu, " "expected WAIT_OBJECT_0\n", ret ); bThreadResult = FAIL; goto done; } /* call SleepEx to activate any queued APCs */ ret = SleepEx(ChildThreadSleepTime, TRUE); if (ret != WAIT_IO_COMPLETION) { Trace( "ERROR:SleepEx() call returned %lu, " "expected WAIT_IO_COMPLETION\n", ret ); bThreadResult = FAIL; goto done; } /* everything passed here */ bThreadResult = PASS; done: /* signal the main thread that we're finished */ if( ! SetEvent( hSyncEvent1 ) ) { Trace( "ERROR:%lu:SetEvent() call failed\n", GetLastError() ); bThreadResult = FAIL; } /* return success or failure */ return bThreadResult; }
unsigned int WINAPI ClientHandlingThread( LPVOID lpParam ) { LThreadType = THREAD_CLIENT; PendingAcceptList* pAcceptList = (PendingAcceptList*)lpParam; /// Timer HANDLE hTimer = CreateWaitableTimer( NULL, FALSE, NULL ); if ( hTimer == NULL ) return -1; LARGE_INTEGER liDueTime; liDueTime.QuadPart = -10000000; ///< 1초 후부터 동작 if ( !SetWaitableTimer( hTimer, &liDueTime, 100, TimerProc, NULL, TRUE ) ) return -1; while ( true ) { SOCKET acceptSock = NULL; /// 새로 접속한 클라이언트 처리 if ( pAcceptList->Consume( acceptSock, false ) ) { /// 소켓 정보 구조체 할당과 초기화 ClientSession* client = GClientManager->CreateClient( acceptSock ); SOCKADDR_IN clientaddr; int addrlen = sizeof( clientaddr ); getpeername( acceptSock, (SOCKADDR*)&clientaddr, &addrlen ); // 클라 접속 처리 if ( false == client->OnConnect( &clientaddr ) ) { client->Disconnect(); } continue; ///< 다시 대기로 } /// 최종적으로 클라이언트들에 쌓인 send 요청 처리 GClientManager->FlushClientSend(); /// APC Queue에 쌓인 작업들 처리 SleepEx( INFINITE, TRUE ); } CloseHandle( hTimer ); return 0; }
void cairo_perf_yield (void) { /* try to deactivate this thread until the scheduler calls it again */ #if defined(__OS2__) DosSleep (0); #elif defined(_WIN32) SleepEx(0, TRUE); #elif defined(_POSIX_PRIORITY_SCHEDULING) sched_yield (); #else sleep (0); #endif }
bool MagicFun2( HDC hSrcDC , int x , int y , HDC hDestDC , int xd , int yd , int width , int height , int nDelay, int nStep) { if( nStep < 2 ) nStep = 2; int num=height/nStep; for(int i=0;i<nStep;i++) { for(int j=0;j<num;j++) { BitBlt( hDestDC,xd,yd+j*nStep+i,width,1, hSrcDC,x, y+j*nStep+i,SRCCOPY); } SleepEx( nDelay); } BitBlt( hDestDC , xd , yd , width , height ,hSrcDC,x,y,SRCCOPY); return TRUE; }
void xsleep (double seconds) { #ifdef HAVE_USLEEP if (seconds > 1000) { /* Explained in utils.c. */ sleep (seconds); seconds -= (long) seconds; } usleep (seconds * 1000000); #else /* not HAVE_USLEEP */ SleepEx ((DWORD) (seconds * 1000 + .5), FALSE); #endif /* not HAVE_USLEEP */ }
/* * verifyconnect() returns TRUE if the connect really has happened. */ static bool verifyconnect( curl_socket_t sockfd, int *error ) { bool rc = TRUE; #ifdef SO_ERROR int err = 0; socklen_t errSize = sizeof( err ); #ifdef WIN32 /* * In October 2003 we effectively nullified this function on Windows due to * problems with it using all CPU in multi-threaded cases. * * In May 2004, we bring it back to offer more info back on connect failures. * Gisle Vanem could reproduce the former problems with this function, but * could avoid them by adding this SleepEx() call below: * * "I don't have Rational Quantify, but the hint from his post was * ntdll::NtRemoveIoCompletion(). So I'd assume the SleepEx (or maybe * just Sleep(0) would be enough?) would release whatever * mutex/critical-section the ntdll call is waiting on. * * Someone got to verify this on Win-NT 4.0, 2000." */ SleepEx( 0, FALSE ); #endif if ( -1 == getsockopt( sockfd, SOL_SOCKET, SO_ERROR, (void *)&err, &errSize ) ) { err = Curl_ourerrno(); } if ( ( 0 == err ) || ( EISCONN == err ) ) { /* we are connected, awesome! */ rc = TRUE; } else { /* This wasn't a successful connect */ rc = FALSE; } if ( error ) { *error = err; } #else (void)sockfd; if ( error ) { *error = Curl_ourerrno(); } #endif return rc; }
/* Signal handling thread */ static DWORD WINAPI pg_signal_thread(LPVOID param) { char pipename[128]; HANDLE pipe = pgwin32_initial_signal_pipe; snprintf(pipename, sizeof(pipename), "\\\\.\\pipe\\pgsignal_%lu", GetCurrentProcessId()); for (;;) { BOOL fConnected; HANDLE hThread; if (pipe == INVALID_HANDLE_VALUE) { pipe = CreateNamedPipe(pipename, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, 16, 16, 1000, NULL); if (pipe == INVALID_HANDLE_VALUE) { write_stderr("could not create signal listener pipe: error code %d; retrying\n", (int) GetLastError()); SleepEx(500, FALSE); continue; } } fConnected = ConnectNamedPipe(pipe, NULL) ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED); if (fConnected) { hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) pg_signal_dispatch_thread, (LPVOID) pipe, 0, NULL); if (hThread == INVALID_HANDLE_VALUE) write_stderr("could not create signal dispatch thread: error code %d\n", (int) GetLastError()); else CloseHandle(hThread); } else /* Connection failed. Cleanup and try again */ CloseHandle(pipe); /* Set up so we create a new pipe on next loop */ pipe = INVALID_HANDLE_VALUE; } return 0; }
void win32_directory_monitor_destroy_record(DirectoryMonitorRecord* record) { // This is invoked because it forces all completion notifications // to happen one last time. CancelIo(record->handle); // Wait for i/o operations to finish up. if (!HasOverlappedIoCompleted(&record->async_data)) { SleepEx(5, TRUE); } MEMORY2_DEALLOC(_monitor_state->allocator, record->buffer); CloseHandle(record->handle); MEMORY2_DELETE(_monitor_state->allocator, record); }
/* ---------------------------------------------------------------------- * * Function Definitions * ---------------------------------------------------------------------- */ void lc_usleep (unsigned long t) { #if defined (WIN32) /* This function will usually sleep too long. For example, if t == 0 (e.g. 1 usec), thread will sleep for the remainder of its timeslice, which might be 20 ms. */ SleepEx (t / 1000, FALSE); #else struct timeval timeout; timeout.tv_sec = t / 1000000; timeout.tv_usec = t - 1000000 * timeout.tv_sec; select (1, NULL, NULL, NULL, &timeout); #endif }
int nanosleep(const struct timespec *req, struct timespec *rem) { DWORD milliseconds; if (req->tv_sec < 0 || req->tv_nsec < 0 || req->tv_nsec > NANOSEC_BOUND) { SetLastError(EINVAL); return -1; } milliseconds = req->tv_sec * MILLISEC_PER_SEC + req->tv_nsec / NANOSEC_PER_MILLISEC; SleepEx(milliseconds, TRUE); if (rem) memset(rem, 0, sizeof(*rem)); return 0; }
/* * pg_usleep --- delay the specified number of microseconds. * * NOTE: although the delay is specified in microseconds, the effective * resolution is only 1/HZ, or 10 milliseconds, on most Unixen. Expect * the requested delay to be rounded up to the next resolution boundary. * * On machines where "long" is 32 bits, the maximum delay is ~2000 seconds. */ void pg_usleep(long microsec) { if (microsec > 0) { #ifndef WIN32 struct timeval delay; delay.tv_sec = microsec / 1000000L; delay.tv_usec = microsec % 1000000L; (void) select(0, NULL, NULL, NULL, &delay); #else SleepEx((microsec < 500 ? 1 : (microsec + 500) / 1000), FALSE); #endif } }
// LCOV_EXCL_START :dpm void NADebug() { if (getenv("SQL_DEBUGLOOP") == NULL) DebugBreak(); else {Int32 dbgv = 1; Int32 woody; // as in Woody Allen aka Sleeper. while (dbgv == 1) { woody = SleepEx(100,FALSE); // delay 0.1 seconds dbgv = 2 - dbgv; // another way of saying, "leave dbgv at 1" }; } }
void FileReader::readFile(char* filename, LPVOID buffer, OVERLAPPED& ol, uint32& dwBytesRead, uint32 bufferSize) { if (DEBUG) { printf("Reading %s\n", filename); } bool flag = ReadFileEx(this->hFile, (char*)buffer, bufferSize, &ol, FileIOCompletionRoutine); if (DEBUG && !flag) { //DisplayError(TEXT("ReadFile")); printf("Terminal failure: Unable to read from file.\n GetLastError=%08x\n", GetLastError()); return; } SleepEx(5000, TRUE); dwBytesRead = ol.InternalHigh; }
bool test_new_thread_pool() {//success is true, failure is false int sockErr; WSADATA lpWSAData={0}; sockErr=WSAStartup(0x202, &lpWSAData); sListen=WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED); if(INVALID_SOCKET==sListen){ DebugBreak(); } GUID GuidDisconnectEx = WSAID_DISCONNECTEX; DWORD dwBytes; WSAIoctl(sListen, SIO_GET_EXTENSION_FUNCTION_POINTER, &GuidDisconnectEx, sizeof (GuidDisconnectEx), &DisconnectEx, sizeof (DisconnectEx), &dwBytes, NULL, NULL); InitializeThreadpoolEnvironment(&tEnvrion); pMainPool=CreateThreadpool(NULL); pCleanup=CreateThreadpoolCleanupGroup(); SetThreadpoolCallbackCleanupGroup(&tEnvrion, pCleanup, 0); SetThreadpoolCallbackPool(&tEnvrion, pMainPool); pListen=CreateThreadpoolIo((HANDLE)sListen, acceptingIoThreadProc, 0, &tEnvrion); sockaddr_in service={0}; service.sin_family=AF_INET; service.sin_port=htons(8080); sockErr=bind(sListen, (SOCKADDR *) &service, sizeof(service)); if(SOCKET_ERROR==sockErr){ DebugBreak(); } sockErr=listen(sListen, SOMAXCONN); if(SOCKET_ERROR==sockErr){ DebugBreak(); } for(int i=0; i<numSockets; i++){ ntpAddAcceptSocket(sListen); } OutputDebugString(TEXT("CloseThreadpoolCleanupGroupMembers waiting\n")); SleepEx(INFINITE, TRUE); CloseThreadpoolCleanupGroupMembers(pCleanup, FALSE, NULL); OutputDebugString(TEXT("CloseThreadpoolCleanupGroupMembers done\n")); return false; }