本文整理汇总了C++中Host::addresses方法的典型用法代码示例。如果您正苦于以下问题:C++ Host::addresses方法的具体用法?C++ Host::addresses怎么用?C++ Host::addresses使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Host
的用法示例。
在下文中一共展示了Host::addresses方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: connect
void Server::connect(SocksClientSocket &me, const Host &host, IPPort port)
{
#if 1
//@@@ should be using Hostname (server resolution) mode, but this won't get us
//@@@ any useful peer address to use for bind relaying. Need to rethink this scenario.
set<IPAddress> addrs = host.addresses();
for (set<IPAddress>::const_iterator it = addrs.begin(); it != addrs.end(); it++) {
try {
IPSockAddress addr(*it, port);
connect(me, addr);
return;
} catch (const UnixError &err) {
errno = err.error;
}
}
// exhausted
UnixError::throwMe();
#else
open(me, me);
Message request(socksConnect, host.name().c_str(), port);
request.send(me);
Message reply(me);
me.mLocalAddress = reply.address();
//me.mPeerAddress = not provided by Socks5 protocol;
secdebug("socks", "%d socks connected to %s", me.fd(), host.name().c_str());
#endif
}
示例2: connect
void Server::connect(SocksClientSocket &me, const Host &host, IPPort port)
{
// Socks4 has no name resolution support. Do it here
//@@@ error reporting sucks here
set<IPAddress> addrs = host.addresses();
for (set<IPAddress>::const_iterator it = addrs.begin(); it != addrs.end(); it++) {
try {
IPSockAddress addr(*it, port);
connect(me, addr);
return;
} catch (const UnixError &err) {
errno = err.error;
}
}
// exhausted
UnixError::throwMe();
}
示例3: connect
//
// Connect to a Host object.
// This version of connect performs nontrivial work and makes interesting decisions.
//
void Socket::connect(const Host &host, IPPort port)
{
//@@@ use two-step stutter algorithm?
//@@@ randomize order?
//@@@ keep worked-recently information?
//@@@ what about nonblocking operation?
set<IPAddress> addrs = host.addresses();
for (set<IPAddress>::const_iterator it = addrs.begin(); it != addrs.end(); it++) {
const IPSockAddress address(*it, port);
if (::connect(fd(), address, sizeof(IPSockAddress)) == 0) {
secdebug("sockio", "%d connect to %s", fd(), string(address).c_str());
return;
}
}
// no joy on any of the candidate addresses. Throw last error
//@@@ clean up errno?
UnixError::throwMe();
}