Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
IOCompletionPort.cpp
Package: SwordOnline.rar [view]
Upload User: dzyhzl
Upload Date: 2019-04-29
Package Size: 56270k
Code Size: 2k
Category:
Game Server Simulator
Development Platform:
C/C++
- #include "stdafx.h"
- #include "IOCompletionPort.h"
- #include "Win32Exception.h"
- #include "Macro.h"
- /*
- * namespace OnlineGameLib::Win32
- */
- namespace OnlineGameLib {
- namespace Win32 {
- CIOCompletionPort::CIOCompletionPort( size_t maxConcurrency )
- : m_iocp( ::CreateIoCompletionPort( INVALID_HANDLE_VALUE, NULL, 0, maxConcurrency ) )
- {
- if ( m_iocp == 0 )
- {
- throw CWin32Exception( _T("CIOCompletionPort::CIOCompletionPort() - CreateIoCompletionPort"), ::GetLastError() );
- }
- }
- CIOCompletionPort::~CIOCompletionPort()
- {
- SAFE_CLOSEHANDLE( m_iocp );
- }
- void CIOCompletionPort::AssociateDevice( HANDLE hDevice, ULONG_PTR completionKey )
- {
- if ( m_iocp != ::CreateIoCompletionPort( hDevice,
- m_iocp,
- completionKey,
- 0 ) )
- {
- throw CWin32Exception( _T("CIOCompletionPort::AssociateDevice() - CreateIoCompletionPort"), ::GetLastError() );
- }
- }
- void CIOCompletionPort::PostStatus( ULONG_PTR completionKey,
- DWORD dwNumBytes /* = 0 */,
- OVERLAPPED *pOverlapped /* = 0 */)
- {
- if ( 0 == ::PostQueuedCompletionStatus( m_iocp,
- dwNumBytes,
- completionKey,
- pOverlapped ) )
- {
- throw CWin32Exception( _T("CIOCompletionPort::PostStatus() - PostQueuedCompletionStatus"), ::GetLastError() );
- }
- }
- DWORD CIOCompletionPort::GetStatus( ULONG_PTR *pCompletionKey,
- PDWORD pdwNumBytes,
- OVERLAPPED **ppOverlapped )
- {
- if ( 0 == ::GetQueuedCompletionStatus( m_iocp,
- pdwNumBytes,
- pCompletionKey,
- ppOverlapped,
- INFINITE ) )
- {
- return ::GetLastError();
- }
- return S_OK;
- }
- DWORD CIOCompletionPort::GetStatus( ULONG_PTR *pCompletionKey,
- PDWORD pdwNumBytes,
- OVERLAPPED **ppOverlapped,
- DWORD dwMilliseconds)
- {
- if ( 0 == ::GetQueuedCompletionStatus( m_iocp,
- pdwNumBytes,
- pCompletionKey,
- ppOverlapped,
- dwMilliseconds ) )
- {
- DWORD lastError = ::GetLastError();
- if ( lastError != WAIT_TIMEOUT )
- {
- return lastError;
- }
- return S_FALSE;
- }
- return S_OK;
- }
- } // End of namespace OnlineGameLib
- } // End of namespace Win32