#pragma	once

#include "NetBridge_Base.h"


//test 1

class CNetBridge_IOCP : public CNetBridge_Base
{
public:
	CNetBridge_IOCP(void);
	virtual ~CNetBridge_IOCP(void);

	virtual int			Init				();
	virtual	int			Host				( DWORD dwIP , WORD wPort, CEventObj* pEventObj, BOOL bCompress = false , BOOL bEncryption = false );
	virtual int			Connect				( DWORD dwIP , WORD wPort, CEventObj* pEventObj );

	virtual void		_Send				( DWORD dwNetID, DWORD dwSize, PVOID pBuffer, DWORD dwPriority, DWORD dwFlag );

	virtual void		SendToAll			( DWORD dwSize, PVOID pPacket, DWORD dwPriority );
	virtual void		Close				( DWORD dwNetID );

	

	virtual bool		CheckNetID			( DWORD dwNetID );
	virtual DWORD		GetNumOfConnections	();

	virtual int			GetSendQueueSize	();


	static HANDLE		m_CompletionPort;
	static HANDLE		m_CompThreads[ DF_NB_MAX_COMPLETION_THREAD_COUNT ];


	//======================================================================================================
//private:
	static DWORD WINAPI	Thread_Completion	( PVOID pParam );

	void				ProcessBuffer		( CNetSocket* pSocket, CBuffer* pBuffer );

	void				Handle_Accept		( CNetSocket* pSocket, CBuffer* pBuffer, HANDLE CompletionPort, DWORD dwBytesTransfer );
	void				Handle_Recv			( CNetSocket* pSocket, CBuffer* pBuffer, HANDLE CompletionPort, DWORD dwBytesTransfer );
	void				Handle_Send			( CNetSocket* pSocket, CBuffer* pBuffer, HANDLE CompletionPort, DWORD dwBytesTransfer );
	void				Handle_Disconnect	( CNetSocket* pSocket, CBuffer* pBuffer, HANDLE CompletionPort, DWORD dwBytesTransfer );
	void				Handle_Compress		( CNetSocket* pSocket, CBuffer* pBuffer, HANDLE CompletionPort, DWORD dwBytesTransfer );
	
	void				Post_Compress		( CNetSocket* pSocket, CBuffer* pBuffer );
	void				Post_Send			( CNetSocket* pSocket, CBuffer* pBuffer );
	void				Post_Recv			( CNetSocket* pSocket );
	void				Post_Accept			( CNetSocket* pSocket, CBuffer* pBuffer );	

	//-------------------------------------------------------------------------------------------------------
	//priority_queue< DWORD , CNetSocket* >	m_pqClosingSocket;
};