本文整理汇总了C++中SocketAddress::GetAF方法的典型用法代码示例。如果您正苦于以下问题:C++ SocketAddress::GetAF方法的具体用法?C++ SocketAddress::GetAF怎么用?C++ SocketAddress::GetAF使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketAddress
的用法示例。
在下文中一共展示了SocketAddress::GetAF方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: defined
//----------------------------------------------------------------------------
void SocketImpl::Bind6(const SocketAddress& address, bool reuseAddress,
bool ipV6Only)
{
#if defined(PX2_HAVE_IPV6)
if (address.GetFamily() != IPAddress::IPv6)
{
assertion(false, "SocketAddress must be an IPv6 address");
}
if (mSocket == PX2_INVALID_SOCKET)
{
Init(address.GetAF());
}
#ifdef IPV6_V6ONLY
SetOption(IPPROTO_IPV6, IPV6_V6ONLY, ipV6Only ? 1 : 0);
#else
if (ipV6Only)
{
assertion(false, "IPV6_V6ONLY not defined.");
}
#endif
if (reuseAddress)
{
SetReuseAddress(true);
SetReusePort(true);
}
int rc = ::bind(mSocket, address.GetAddr(), address.GetAddrLength());
if (rc != 0)
{
NetError::Error(address.ToString());
}
#else
assertion(false, "No IPv6 support available.\n");
#endif
}
示例2: Bind
//----------------------------------------------------------------------------
void SocketImpl::Bind(const SocketAddress& address, bool reuseAddress)
{
if (mSocket == PX2_INVALID_SOCKET)
{
Init(address.GetAF());
}
if (reuseAddress)
{
SetReuseAddress(true);
SetReusePort(true);
}
int rc = ::bind(mSocket, address.GetAddr(), address.GetAddrLength());
if (rc != 0)
{
NetError::Error(address.ToString());
}
}
示例3: ConnectNB
//----------------------------------------------------------------------------
int SocketImpl::ConnectNB(const SocketAddress& address)
{
if (mSocket == PX2_INVALID_SOCKET)
{
Init(address.GetAF());
}
SetBlocking(false);
int rc = ::connect(mSocket, address.GetAddr(), address.GetAddrLength());
if (rc != 0)
{
int err = NetError::LastError();
if (err != PX2_EINPROGRESS && err != PX2_EWOULDBLOCK)
{
NetError::Error(err, address.ToString());
}
}
return rc;
}
示例4: ConnectB
//----------------------------------------------------------------------------
int SocketImpl::ConnectB(const SocketAddress& address,
const Timespan& timeout)
{
if (mSocket == PX2_INVALID_SOCKET)
{
Init(address.GetAF());
}
SetBlocking(false);
int rc = ::connect(mSocket, address.GetAddr(), address.GetAddrLength());
if (rc != 0)
{
int err = NetError::LastError();
if (err != PX2_EINPROGRESS && err != PX2_EWOULDBLOCK)
{
NetError::Error(err, address.ToString());
}
if (!Poll(timeout, SELECT_READ | SELECT_WRITE | SELECT_ERROR))
{
assertion(false, "connect timed out:%s", address.ToString());
}
err = GetSocketError();
if (err != 0)
{
NetError::Error(err);
}
}
SetBlocking(true);
return rc;
}