当前位置: 首页>>代码示例>>C++>>正文


C++ SocketAddress::GetAddr方法代码示例

本文整理汇总了C++中SocketAddress::GetAddr方法的典型用法代码示例。如果您正苦于以下问题:C++ SocketAddress::GetAddr方法的具体用法?C++ SocketAddress::GetAddr怎么用?C++ SocketAddress::GetAddr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SocketAddress的用法示例。


在下文中一共展示了SocketAddress::GetAddr方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
开发者ID:JamShan,项目名称:Phoenix3D_2.1,代码行数:36,代码来源:PX2SocketImpl.cpp

示例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());
	}
}
开发者ID:JamShan,项目名称:Phoenix3D_2.1,代码行数:21,代码来源:PX2SocketImpl.cpp

示例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;
}
开发者ID:JamShan,项目名称:Phoenix3D_2.1,代码行数:24,代码来源:PX2SocketImpl.cpp

示例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;
}
开发者ID:JamShan,项目名称:Phoenix3D_2.1,代码行数:38,代码来源:PX2SocketImpl.cpp

示例5: SendTo

//----------------------------------------------------------------------------
int SocketImpl::SendTo (const void* buffer, int length, 
	const SocketAddress& address, int flags)
{
	int rc;
	//do
	{
		if (mSocket == PX2_INVALID_SOCKET)
		{
			assertion(false, "Invalid socket.\n");
		}

		rc = ::sendto(mSocket, reinterpret_cast<const char*>(buffer), length, 
			flags, address.GetAddr(), address.GetAddrLength());

	}	
	//while (mIsBlocking && rc < 0 && LastError() == PX2_EINTR);

	if (rc < 0)
	{
		NetError::Error();
	}

	return rc;
}
开发者ID:JamShan,项目名称:Phoenix3D_2.1,代码行数:25,代码来源:PX2SocketImpl.cpp


注:本文中的SocketAddress::GetAddr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。