// WMWinSocket2.h: interface for the WMWinSocket2 class.
//
//////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2001 Robert Cunnings. All rights reserved.
//
// You may copy, modify, distribute or publish this code free of charge.
//
// NO WARRANTY: This software is provided AS IS, without warranty of any kind.
//
//////////////////////////////////////////////////////////////////////
//
// WMWinSocket2 class - a class for Winsock 2 client support.
// 
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_WMWINSOCKET2_H__01AC256E_BBC1_456D_A056_ABDAA198B9A3__INCLUDED_)
#define AFX_WMWINSOCKET2_H__01AC256E_BBC1_456D_A056_ABDAA198B9A3__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "Winsock2.h"

#include <deque>
using namespace std;

// version of Winsock we need 
#define VERSION_MAJOR	2 
#define VERSION_MINOR   0 

class WMWinSocket2  
{
public:
	WMWinSocket2(DWORD dwTimeOut);
	virtual ~WMWinSocket2();

	// attributes
	bool IsInitialized() { return m_bInitialized; }
	bool IsConnected() { return m_bConnected; }

	// operations
	bool Connect(SOCKADDR_IN *pAddress);
	bool Send(char *pszBuffer, int nBufLen);
	bool Recv(char *pszBuffer, int nBufLen, int *pnNumBytes);
	void Clear();

	// event handlers
	virtual bool OnSockTimeout() {return true;}
	virtual bool OnSockConnect() {return true;}
	virtual bool OnSockRead() {return true;}
	virtual bool OnSockWrite() {return true;}
	virtual void OnSockClose() {}

	// last error
	int				m_nLastError;

private:
	// attributes
	bool			m_bInitialized;
	bool			m_bConnected;
	// WinSock 2
	DWORD			m_dwTimeOut;
	SOCKET			m_hSocket;
	WSAEVENT		m_hEvent;
	// write queue
	deque<LPWSABUF>	m_dequeDataOut;
};

#endif // !defined(AFX_WMWINSOCKET2_H__01AC256E_BBC1_456D_A056_ABDAA198B9A3__INCLUDED_)
