Beispiel #1
0
	void Server::WorkerProc()
	{
		BOOL status;
		DWORD num_transferred = 0;
		ULONG_PTR key;
		LPOVERLAPPED pOver = NULL;

		while(TRUE)
		{
			status = GetQueuedCompletionStatus(
				m_hIoPort, 
				&num_transferred, &key, &pOver,INFINITE );

			Session* pSession = reinterpret_cast<Session*>(pOver);
			if ( status == FALSE || (num_transferred == 0 && pSession != NULL && !pSession->CanProcessZero()) )
			{
				// An error occurred; reset to a known state.
				if ( pSession != NULL )
				{
					Log(_T("Remote host closed connection."));
					pSession->IssueReset();
				}
			}
			else
			{			
				switch (key)
				{
				case COMPLETION_KEY_IO:
					pSession->OnIoComplete(num_transferred);
					break;
				case COMPLETION_KEY_SHUTDOWN:
					return;
				case COMPLETION_FILE_KEY_IO:
					FileOverlapped* fo = reinterpret_cast<FileOverlapped*>(pOver);
					fo->m_pSession->OnIoComplete(num_transferred);
					break;
				}
			}
		}
	}