1//
2// This file is part of the aMule Project.
3//
4// Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5// Copyright (c) 2002-2011 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6//
7// Any parts of this program derived from the xMule, lMule or eMule project,
8// or contributed by third-party developers are copyrighted by their
9// respective authors.
10//
11// This program is free software; you can redistribute it and/or modify
12// it under the terms of the GNU General Public License as published by
13// the Free Software Foundation; either version 2 of the License, or
14// (at your option) any later version.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
24//
25
26//
27// Handling incoming connections (up or downloadrequests)
28//
29
30#ifndef CLIENTTCPSOCKET_H
31#define CLIENTTCPSOCKET_H
32
33#include "EMSocket.h"		// Needed for CEMSocket
34
35class CProxyData;
36
37//------------------------------------------------------------------------------
38// CClientTCPSocket
39//------------------------------------------------------------------------------
40
41class CUpDownClient;
42class CPacket;
43class CTimerWnd;
44
45class CClientTCPSocket : public CEMSocket
46{
47public:
48	CClientTCPSocket(CUpDownClient* in_client = NULL, const CProxyData *ProxyData = NULL);
49	virtual ~CClientTCPSocket();
50
51	void		Disconnect(const wxString& strReason);
52
53	bool		InitNetworkData();
54
55	bool		CheckTimeOut();
56
57	void		Safe_Delete();
58	void		Safe_Delete_Client();
59
60	bool		ForDeletion() const { return m_ForDeletion; }
61
62	void		OnConnect(int nErrorCode);
63	void		OnSend(int nErrorCode);
64	void		OnReceive(int nErrorCode);
65
66	void		OnClose(int nErrorCode);
67	void		OnError(int nErrorCode);
68
69	uint32		GetRemoteIP() const { return m_remoteip; }
70
71	CUpDownClient* GetClient() { return m_client; }
72
73	virtual void SendPacket(CPacket* packet, bool delpacket = true, bool controlpacket = true, uint32 actualPayloadSize = 0);
74    virtual SocketSentBytes SendControlData(uint32 maxNumberOfBytesToSend, uint32 overchargeMaxBytesToSend);
75    virtual SocketSentBytes SendFileAndControlData(uint32 maxNumberOfBytesToSend, uint32 overchargeMaxBytesToSend);
76
77protected:
78	virtual bool PacketReceived(CPacket* packet);
79
80private:
81	CUpDownClient*	m_client;
82
83	bool	ProcessPacket(const byte* packet, uint32 size, uint8 opcode);
84	bool	ProcessExtPacket(const byte* packet, uint32 size, uint8 opcode);
85	bool	ProcessED2Kv2Packet(const byte* packet, uint32 size, uint8 opcode);
86	void	ResetTimeOutTimer();
87	void	SetClient(CUpDownClient* client);
88
89	bool	m_ForDeletion; // 0.30c (Creteil), set as bool
90	uint32	timeout_timer;
91	uint32	m_remoteip;
92};
93
94#endif // CLIENTTCPSOCKET_H
95// File_checked_for_headers
96