#pragma	once

#include <Windows.h>

typedef void (*PFERRMSG)( DWORD dwLevel, DWORD dwErrID,  char *format,... );

//定義 Winsock 所使用的模式
enum EM_WINSOCK_IO_MODE
{
	OVERLAPPED_MODE				=0,
	IOCP_MODE					
};

//定義連線所使用的模式	
enum EM_CONNECT_MODE
{
	EM_CONNECT_ONCE				=0,
	EM_CONNECT_KEEPTRY					
};

enum EM_SOCKET_STAUTS
{
	EM_SOCKET_UNCONNECT				=0,
	EM_SOCKET_CONNECTED				,
	EM_SOCKET_WAIT_CLOSE			,		// 程式要求關畢連線, 等待資料發送完畢
	EM_SOCKET_CLOSING				,
};

enum EM_AUTHORIZE_STAUTS
{
	EM_AUTHORIZE_OKAY				=0,
	EM_AUTHORIZE_WAIT_AUTHORIZE		,
	EM_AUTHORIZE_WAIT_PASS			,		// Connect out 方為等待收取認證資料, Connect In 方為等待連入
	EM_AUTHORIZE_CHECK_AUTHORIZE	,		// Connect out 方為等待收取認證資料, Connect In 方為等待連入
};

//#define DF_CONNECT_KEEPTRY_MAXTIME_MS	5000	//持續嘗試連線等待最長的時間

//定義錯誤代碼
enum EM_ERROR_CODE
{
	NB_OK							=0,
	NB_ERR							=-1,
	NB_ERR_UNABLE_LOAD_WINSOCK		=-2,
	NB_ERR_UNABLE_CREATE_IOCP		=-3,
	NB_ERR_UNABLE_CREATE_IOCPTHREAD	=-4,
};

//定義基本設定
#define		DF_MAX_HOST_SOCKET		64		//參照 MAXIMUM_WAIT_OBJECTS 所設的上限


// 錯誤訊息輸出


#define DF_NB_MAX_COMPLETION_THREAD_COUNT 32     // Maximum number of completion threads allowed

#define NBERR					0
#define NBERR_CANTFINDNETID		NBERR + 1

#define DF_NB_PACKETBUFFERSIZE		1024
#define DF_NB_OVERLAPPEDCOUNTER	3

#define DF_TEST_ACCEPTEX

#define DF_TIME_CLOSINGSOCKET	5000	// 當錯誤發生後, 多少秒系統未處理有問題的 Socket. 我們自己將之關畢
#define DF_TIME_RECYCLEDELAY	60000

#define DF_PTAG_PACKETLOG_ANSWER	0x10000000
#define DF_PTAG_PACKETLOG_RQUEST	0x20000000
#define DF_PTAG_COLLECT				0x40000000
#define DF_PTAG_COMORESS			0x80000000
#define DF_PTAG_MASK				0xF0000000
#define DF_PTAG_SIZEMASK			0x0FFFFFFF



/*
#define MSG_PACKET			0
#define	MSG_CONNECTFAILED	1
#define	MSG_CONNECTED		2
#define	MSG_NEWCONNECTION	3
#define MSG_ERROR			4
*/

//定義 Buffer 狀態
enum EM_BUFFER_MODE
{
	EM_NULL					= 0,
	EM_ACCEPT				,
	EM_RECV					,
	EM_SEND					,
	EM_COMPRESS				,
};

enum EM_MSG_TYPE
{
	MSG_NULL			=0,
	MSG_RECV			,
	MSG_CONNECT_FAILED	,
	MSG_CONNECT			,
	MSG_ACCEPT			,
	MSG_SEND			,
	MSG_ERROR			,
	MSG_DISCONNECT		,
	MSG_AUTHORIZE	,
};

extern BYTE g_authorize_key[10];
