#pragma once

// 维护一个文件列表,表示需要传输的文件;
typedef struct __STFileList
{
	// 1.本地文件名;
	// 2.文件大小;
	// 3.文件属性;
	// 4.文件指针偏移量;（若为发送方文件列表,该值由接收方返回）
	// 5.
};

// 用于文件更新;
// 1.服务器向所有客户端发送版本更新信息
// 2.客户端接收到有更新指示,主动连接服务端文件服务器下载更新文件;
// 3.服务端提交客户端某部分文件? don't need!

// 服务端文件传输类; 要足够简单;
// Jeff.need make this class as Single mode ?
class CFileTransfer
{
public:
	CFileTransfer(void);
	~CFileTransfer(void);

private:
	SOCKET m_hSocket;		// 监听套接字;
	DWORD  m_dwFilePort;	// 监听端口;

public:

	bool IsOpen() const;
	bool CreateSocket(LPCTSTR pszHost, LPCTSTR pszServiceName, int nFamily, int nType, UINT uOptions = 0);
	bool ConnectTo(LPCTSTR pszHostName, LPCTSTR pszRemote, LPCTSTR pszServiceName, int nFamily, int nType);
	void Close();

	SOCKET GetSocket() const { return m_hSocket;};

    int GetSocketType() const;

    bool Attach(SOCKET sock);
    SOCKET Detach();

   
    DWORD Read(LPBYTE lpBuffer, DWORD dwSize, LPSOCKADDR lpAddrIn = NULL, DWORD dwTimeout = INFINITE);
    DWORD Write(const LPBYTE lpBuffer, DWORD dwCount, const LPSOCKADDR lpAddrIn = NULL, DWORD dwTimeout = INFINITE);

    bool GetSockName(SockAddrIn& saddr_in) const;

    bool GetPeerName(SockAddrIn& saddr_in) const;

    bool AddMembership(LPCTSTR pszIPAddr, LPCTSTR pszNIC);

    bool DropMembership(LPCTSTR pszIPAddr, LPCTSTR pszNIC);

    static bool InitLibrary(WORD wVersion);

    static bool ReleaseLibrary();

    static SOCKET WaitForConnection(SOCKET sock);

    static bool ShutdownConnection(SOCKET sock);

};
