// Connection.h: interface for the WMConnection class.
//
//////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000, 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.
//
//////////////////////////////////////////////////////////////////////
//
// WMConnection class - a class for Winsock2 support.
// 
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_WMCONNECTION_H__F210502A_1314_11D3_9E16_00105AABC815__INCLUDED_)
#define AFX_WMCONNECTION_H__F210502A_1314_11D3_9E16_00105AABC815__INCLUDED_

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

#include <string>
using namespace std;

#define RCV_BUFFER_SIZE 4096

class WMConnection  
{
public:
	WMConnection();
	virtual ~WMConnection();

	bool Initialize(SOCKET hSocket);
	void Shutdown();
	bool ResolveName(bool bUseDNS, string& strPeerName);

 	typedef enum {
		SEND_IO_PENDING,
		SEND_WOULDBLOCK,
		SEND_SUCCESS,
		SEND_RESET,
		SEND_ERROR
	} SENDSTATUS;


 	typedef enum {
		RCV_IO_PENDING,
		RCV_WOULDBLOCK,
		RCV_SUCCESS,
		RCV_CLOSED,
		RCV_RESET,
		RCV_ERROR
	} RCVSTATUS;

	SENDSTATUS SendBlock(LPWSABUF pBlock);
	RCVSTATUS  RcvBlock(LPWSABUF pBlock);
	RCVSTATUS  PostAsychRcv();

	// socket info
	SOCKET m_hSocket;
	// 10-6-2001
	// WSAOVERLAPPED structs must be valid for duration
	// of any call to WSARecv or WSASend so make a member
	// Thanks to Jeremy Frens
	WSAOVERLAPPED m_OverlappedRcv;
    WSAOVERLAPPED m_OverlappedSend;
	// recv data
	WSABUF m_RecvBuffer;
	DWORD m_dwNumRecvBytes;
	char m_szRecvBuffer[RCV_BUFFER_SIZE];
	// peer stuff
	string m_strPeerAddress;
	string m_strPeerName;
};


#endif // !defined(AFX_WMCONNECTION_H__F210502A_1314_11D3_9E16_00105AABC815__INCLUDED_)
