#ifndef	__WV_NETWORKING
#define __WV_NETWORKING
#include "Common.h"
#include "Buffer.h"
#include "List.h"


#define IOCPMSG_BEGINDISCONNECT	1

#define GetProtocolDataPtr(lpConnection)		(LPVOID)(((ULONG_PTR)(lpConnection)) + sizeof(CONNECTION))
#define SendCreateMessage(lpConnection)			(lpConnection)->lpProc((lpConnection), MSG_CREATE, 0, 0)
#define PostIOCPMessage(lpConnection, dwMsg)	PostQueuedCompletionStatus((lpConnection)->lpIociParent->hIocp, (dwMsg), (ULONG_PTR)(lpConnection), NULL)

LPIOCPINFO		CreateIocpServer();
LPCONNECTION	AddConnection(LPIOCPINFO lpIoci, SOCKET s, LPPROTOCOLPROC lpProc, ULONG cDataSize, DWORD dwRemoteAddr, USHORT uRemotePort);
VOID			BeginDisconnect(LPCONNECTION lpCon);
VOID			WaitForDisconnect(LPCONNECTION lpCon);
VOID			DestroyConnection(LPCONNECTION lpCon);
VOID			DestroyIocpServer(LPIOCPINFO lpIoci);

VOID			SendBuffer(LPCONNECTION lpCon, LPBUFFER lpBuf, ULONG cPacketSize);
VOID			RecvBuffer(LPCONNECTION lpCon, LPBUFFER lpBuf);

BOOL			ConfigureSocket(SOCKET s);
SOCKET			ConnectTo(LPENDPOINT lpEp);

VOID			AddOverlappedOp(LPCONNECTION lpCon);
VOID			RemoveOverlappedOp(LPCONNECTION lpCon);


#endif //__WV_NETWORKING