1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152 | //
// This file is part of the aMule Project.
//
// Copyright (c) 2004-2011 Stu Redman ( sturedman@amule.org )
// Copyright (c) 2004-2011 aMule Team ( admin@amule.org / http://www.amule.org )
//
// Any parts of this program derived from the xMule, lMule or eMule project,
// or contributed by third-party developers are copyrighted by their
// respective authors.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
//
//
// Implementation of amuleIPV4Address for wxWidgets sockets
// (Implementation for Asio is in LibSocketAsio.cpp
//
#include "LibSocket.h"
#include "Logger.h"
#include "amuleIPV4Address.h"
class CamuleIPV4Endpoint : public wxIPV4address {
public:
CamuleIPV4Endpoint() {}
CamuleIPV4Endpoint(const CamuleIPV4Endpoint & impl) : wxIPV4address(impl) {}
/// operator wxSockAddress& () { return * this; }
};
bool CLibSocket::Connect(amuleIPV4Address& adr, bool wait)
{
return wxSocketClient::Connect(adr.GetEndpoint(), wait);
}
bool CLibSocket::GetPeer(amuleIPV4Address& adr)
{
return wxSocketClient::GetPeer(adr.GetEndpoint());
}
void CLibSocket::SetLocal(amuleIPV4Address& local)
{
wxSocketClient::SetLocal(local.GetEndpoint());
}
CLibSocketServer::CLibSocketServer(const amuleIPV4Address &address, wxSocketFlags flags) : wxSocketServer(address.GetEndpoint(), flags)
{
}
CLibUDPSocket::CLibUDPSocket(amuleIPV4Address &address, wxSocketFlags flags) : wxDatagramSocket(address.GetEndpoint(), flags)
{
}
uint32 CLibUDPSocket::RecvFrom(amuleIPV4Address& addr, void* buf, uint32 nBytes)
{
wxDatagramSocket::RecvFrom(addr.GetEndpoint(), buf, nBytes);
return wxDatagramSocket::LastCount();
}
uint32 CLibUDPSocket::SendTo(const amuleIPV4Address& addr, const void* buf, uint32 nBytes)
{
wxDatagramSocket::SendTo(addr.GetEndpoint(), buf, nBytes);
return wxDatagramSocket::LastCount();
}
amuleIPV4Address::amuleIPV4Address()
{
m_endpoint = new CamuleIPV4Endpoint();
}
amuleIPV4Address::amuleIPV4Address(const amuleIPV4Address &a)
{
*this = a;
}
amuleIPV4Address::~amuleIPV4Address()
{
delete m_endpoint;
}
amuleIPV4Address& amuleIPV4Address::operator=(const amuleIPV4Address &a)<--- 'operator=' should check for assignment to self to avoid problems with dynamic memory. [+]'operator=' should check for assignment to self to ensure that each block of dynamically allocated memory is owned and managed by only one instance of the class.
{
m_endpoint = new CamuleIPV4Endpoint(* a.m_endpoint);
return *this;
}
bool amuleIPV4Address::Hostname(const wxString& name)
{
if (name.IsEmpty()) {
return false;
}
return m_endpoint->Hostname(name);
}
bool amuleIPV4Address::Service(uint16 service)
{
if (service == 0) {
return false;
}
return m_endpoint->Service(service);
}
uint16 amuleIPV4Address::Service() const
{
return m_endpoint->Service();
}
bool amuleIPV4Address::IsLocalHost() const
{
return m_endpoint->IsLocalHost();
}
wxString amuleIPV4Address::IPAddress() const
{
return m_endpoint->IPAddress();
}
// Set address to any of the addresses of the current machine.
bool amuleIPV4Address::AnyAddress()
{
bool ret = m_endpoint->AnyAddress();
AddDebugLogLineN(logGeneral, CFormat(wxT("AnyAddress() returned %s")) % IPAddress());
return ret;
}
const CamuleIPV4Endpoint & amuleIPV4Address::GetEndpoint() const
{
return * m_endpoint;
}
CamuleIPV4Endpoint & amuleIPV4Address::GetEndpoint()
{
return * m_endpoint;
}
|