本文整理汇总了C++中SocketAddress::af方法的典型用法代码示例。如果您正苦于以下问题:C++ SocketAddress::af方法的具体用法?C++ SocketAddress::af怎么用?C++ SocketAddress::af使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketAddress
的用法示例。
在下文中一共展示了SocketAddress::af方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InvalidArgumentException
void SocketImpl::bind6(const SocketAddress& address, bool reuseAddress, bool ipV6Only)
{
#if defined(POCO_HAVE_IPv6)
if (address.family() != IPAddress::IPv6)
throw Poco::InvalidArgumentException("SocketAddress must be an IPv6 address");
if (_sockfd == POCO_INVALID_SOCKET)
{
init(address.af());
}
#ifdef IPV6_V6ONLY
setOption(IPPROTO_IPV6, IPV6_V6ONLY, ipV6Only ? 1 : 0);
#else
if (ipV6Only) throw Poco::NotImplementedException("IPV6_V6ONLY not defined.");
#endif
if (reuseAddress)
{
setReuseAddress(true);
setReusePort(true);
}
int rc = ::bind(_sockfd, address.addr(), address.length());
if (rc != 0) error(address.toString());
#else
throw Poco::NotImplementedException("No IPv6 support available");
#endif
}
示例2: connect
void SocketImpl::connect(const SocketAddress& address, const Poco::Timespan& timeout)
{
if (_sockfd == POCO_INVALID_SOCKET)
{
init(address.af());
}
setBlocking(false);
try
{
#if defined(POCO_VXWORKS)
int rc = ::connect(_sockfd, (sockaddr*) address.addr(), address.length());
#else
int rc = ::connect(_sockfd, address.addr(), address.length());
#endif
if (rc != 0)
{
int err = lastError();
if (err != POCO_EINPROGRESS && err != POCO_EWOULDBLOCK)
error(err, address.toString());
if (!poll(timeout, SELECT_READ | SELECT_WRITE | SELECT_ERROR))
throw Poco::TimeoutException("connect timed out", address.toString());
err = socketError();
if (err != 0) error(err);
}
}
catch (Poco::Exception&)
{
setBlocking(true);
throw;
}
setBlocking(true);
}
示例3: sendEPRT
bool FTPClientSession::sendEPRT(const SocketAddress& addr)
{
std::string arg("|");
arg += addr.af() == AF_INET ? '1' : '2';
arg += '|';
arg += addr.host().toString();
arg += '|';
arg += NumberFormatter::format(addr.port());
arg += '|';
std::string response;
int status = sendCommand("EPRT", arg, response);
if (isPositiveCompletion(status))
return true;
else if (isPermanentNegative(status))
return false;
else
throw FTPException("EPRT command failed", response, status);
}
示例4: bind
void SocketImpl::bind(const SocketAddress& address, bool reuseAddress)
{
if (_sockfd == POCO_INVALID_SOCKET)
{
init(address.af());
}
if (reuseAddress)
{
setReuseAddress(true);
setReusePort(true);
}
#if defined(POCO_VXWORKS)
int rc = ::bind(_sockfd, (sockaddr*) address.addr(), address.length());
#else
int rc = ::bind(_sockfd, address.addr(), address.length());
#endif
if (rc != 0) error(address.toString());
}
示例5: connectNB
void SocketImpl::connectNB(const SocketAddress& address)
{
if (_sockfd == POCO_INVALID_SOCKET)
{
init(address.af());
}
setBlocking(false);
#if defined(POCO_VXWORKS)
int rc = ::connect(_sockfd, (sockaddr*) address.addr(), address.length());
#else
int rc = ::connect(_sockfd, address.addr(), address.length());
#endif
if (rc != 0)
{
int err = lastError();
if (err != POCO_EINPROGRESS && err != POCO_EWOULDBLOCK)
error(err, address.toString());
}
}