[Com0com-cvs] hub4com/plugins/tcp comio.cpp, 1.1, 1.2 comio.h, 1.1, 1.2
The virtual serial port driver for Windows.
Brought to you by:
vfrolov
From: Vyacheslav F. <vf...@us...> - 2008-08-26 14:07:04
|
Update of /cvsroot/com0com/hub4com/plugins/tcp In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv4161 Modified Files: comio.cpp comio.h Log Message: Execute OnEvent() in main thread context Index: comio.h =================================================================== RCS file: /cvsroot/com0com/hub4com/plugins/tcp/comio.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** comio.h 27 Mar 2008 17:17:27 -0000 1.1 --- comio.h 26 Aug 2008 14:07:01 -0000 1.2 *************** *** 20,27 **** * * $Log$ * Revision 1.1 2008/03/27 17:17:27 vfrolov * Initial revision * - * */ --- 20,29 ---- * * $Log$ + * Revision 1.2 2008/08/26 14:07:01 vfrolov + * Execute OnEvent() in main thread context + * * Revision 1.1 2008/03/27 17:17:27 vfrolov * Initial revision * */ *************** *** 88,91 **** --- 90,94 ---- PVOID pParameter, BOOLEAN timerOrWaitFired); + static VOID CALLBACK OnEvent(ULONG_PTR pOverlapped); ComPort &port; *************** *** 108,111 **** --- 111,115 ---- PVOID pParameter, BOOLEAN timerOrWaitFired); + static VOID CALLBACK OnEvent(ULONG_PTR pOverlapped); Listener &listener; Index: comio.cpp =================================================================== RCS file: /cvsroot/com0com/hub4com/plugins/tcp/comio.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** comio.cpp 27 Mar 2008 17:17:27 -0000 1.1 --- comio.cpp 26 Aug 2008 14:07:01 -0000 1.2 *************** *** 20,27 **** * * $Log$ * Revision 1.1 2008/03/27 17:17:27 vfrolov * Initial revision * - * */ --- 20,29 ---- * * $Log$ + * Revision 1.2 2008/08/26 14:07:01 vfrolov + * Execute OnEvent() in main thread context + * * Revision 1.1 2008/03/27 17:17:27 vfrolov * Initial revision * */ *************** *** 115,119 **** u_short port = ntohs(snRemote.sin_port); ! cout << "Connect(" << hex << hSock << dec << ", " << ((addr >> 24) & 0xFF) << '.' << ((addr >> 16) & 0xFF) << '.' --- 117,121 ---- u_short port = ntohs(snRemote.sin_port); ! cout << "Connect(" << hex << hSock << dec << ", " << ((addr >> 24) & 0xFF) << '.' << ((addr >> 16) & 0xFF) << '.' *************** *** 266,269 **** --- 268,276 ---- } /////////////////////////////////////////////////////////////// + static HANDLE hThread = INVALID_HANDLE_VALUE; + #ifdef _DEBUG + static DWORD idThread; + #endif /* _DEBUG */ + /////////////////////////////////////////////////////////////// WaitEventOverlapped::WaitEventOverlapped(ComPort &_port, SOCKET hSockWait) : port(_port), *************** *** 271,274 **** --- 278,309 ---- hWait(INVALID_HANDLE_VALUE) { + #ifdef _DEBUG + if (hThread == INVALID_HANDLE_VALUE) { + idThread = ::GetCurrentThreadId(); + } else { + _ASSERTE(idThread == ::GetCurrentThreadId()); + } + #endif /* _DEBUG */ + + if (hThread == INVALID_HANDLE_VALUE) { + if (!::DuplicateHandle(::GetCurrentProcess(), + ::GetCurrentThread(), + ::GetCurrentProcess(), + &hThread, + 0, + FALSE, + DUPLICATE_SAME_ACCESS)) + { + hThread = INVALID_HANDLE_VALUE; + + TraceError( + GetLastError(), + "WaitEventOverlapped::WaitEventOverlapped(): DuplicateHandle() %s", + port.Name().c_str()); + + return; + } + } + hEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL); *************** *** 282,286 **** } ! if (!::RegisterWaitForSingleObject(&hWait, hEvent, OnEvent, this, INFINITE, WT_EXECUTEINIOTHREAD)) { TraceError( GetLastError(), --- 317,321 ---- } ! if (!::RegisterWaitForSingleObject(&hWait, hEvent, OnEvent, this, INFINITE, WT_EXECUTEINWAITTHREAD)) { TraceError( GetLastError(), *************** *** 335,338 **** --- 370,378 ---- BOOLEAN /*timerOrWaitFired*/) { + ::QueueUserAPC(OnEvent, hThread, (ULONG_PTR)pOverlapped); + } + + VOID CALLBACK WaitEventOverlapped::OnEvent(ULONG_PTR pOverlapped) + { WaitEventOverlapped *pOver = (WaitEventOverlapped *)pOverlapped; *************** *** 386,389 **** --- 426,456 ---- hWait(INVALID_HANDLE_VALUE) { + #ifdef _DEBUG + if (hThread == INVALID_HANDLE_VALUE) { + idThread = ::GetCurrentThreadId(); + } else { + _ASSERTE(idThread == ::GetCurrentThreadId()); + } + #endif /* _DEBUG */ + + if (hThread == INVALID_HANDLE_VALUE) { + if (!::DuplicateHandle(::GetCurrentProcess(), + ::GetCurrentThread(), + ::GetCurrentProcess(), + &hThread, + 0, + FALSE, + DUPLICATE_SAME_ACCESS)) + { + hThread = INVALID_HANDLE_VALUE; + + TraceError( + GetLastError(), + "ListenOverlapped::ListenOverlapped(): DuplicateHandle()"); + + return; + } + } + hEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL); *************** *** 396,400 **** } ! if (!::RegisterWaitForSingleObject(&hWait, hEvent, OnEvent, this, INFINITE, WT_EXECUTEINIOTHREAD)) { TraceError( GetLastError(), --- 463,467 ---- } ! if (!::RegisterWaitForSingleObject(&hWait, hEvent, OnEvent, this, INFINITE, WT_EXECUTEINWAITTHREAD)) { TraceError( GetLastError(), *************** *** 445,448 **** --- 512,520 ---- BOOLEAN /*timerOrWaitFired*/) { + ::QueueUserAPC(OnEvent, hThread, (ULONG_PTR)pOverlapped); + } + + VOID CALLBACK ListenOverlapped::OnEvent(ULONG_PTR pOverlapped) + { ListenOverlapped *pOver = (ListenOverlapped *)pOverlapped; |