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


C++ IpAddress::IsValid方法代码示例

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


在下文中一共展示了IpAddress::IsValid方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Listen

	SocketState SocketImpl::Listen(SocketHandle handle, const IpAddress& address, unsigned queueSize, SocketError* error)
	{
		NazaraAssert(handle != InvalidHandle, "Invalid handle");
		NazaraAssert(address.IsValid(), "Invalid address");

		IpAddressImpl::SockAddrBuffer nameBuffer;
		int bufferLength = IpAddressImpl::ToSockAddr(address, nameBuffer.data());

		if (bind(handle, reinterpret_cast<const sockaddr*>(&nameBuffer), bufferLength) == SOCKET_ERROR)
		{
			if (error)
				*error = TranslateWSAErrorToSocketError(WSAGetLastError());

			return SocketState_NotConnected;
		}

		if (listen(handle, queueSize) == SOCKET_ERROR)
		{
			if (error)
				*error = TranslateWSAErrorToSocketError(WSAGetLastError());

			return SocketState_NotConnected;
		}

		if (error)
			*error = SocketError_NoError;

		return SocketState_Bound;
	}
开发者ID:,项目名称:,代码行数:29,代码来源:

示例2: ResolveAddress

	String IpAddress::ResolveAddress(const IpAddress& address, String* service, ResolveError* error)
	{
		NazaraAssert(address.IsValid(), "Invalid address");

		String hostname;
		IpAddressImpl::ResolveAddress(address, &hostname, service, error);

		return hostname;
	}
开发者ID:Ardakaniz,项目名称:NazaraEngine,代码行数:9,代码来源:IpAddress.cpp

示例3: Bind

	SocketState UdpSocket::Bind(const IpAddress& address)
	{
		NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Socket hasn't been created");
		NazaraAssert(address.IsValid(), "Invalid address");

		SocketState state = SocketImpl::Bind(m_handle, address, &m_lastError);
		if (state == SocketState_Bound)
			m_boundAddress = SocketImpl::QuerySocketAddress(m_handle);

		UpdateState(state);
		return state;
	}
开发者ID:DigitalPulseSoftware,项目名称:NazaraEngine,代码行数:12,代码来源:UdpSocket.cpp

示例4: Listen

	SocketState TcpServer::Listen(const IpAddress& address, unsigned int queueSize)
	{
		NazaraAssert(address.IsValid(), "Invalid address");

		Open(address.GetProtocol());

		SocketState state = SocketImpl::Listen(m_handle, address, queueSize, &m_lastError);
		if (state == SocketState_Bound)
			m_boundAddress = SocketImpl::QuerySocketAddress(m_handle);

		UpdateState(state);
		return state;
	}
开发者ID:Ilearn32,项目名称:NazaraEngine,代码行数:13,代码来源:TcpServer.cpp

示例5: SendMultiple

	/*!
	* \brief Sends multiple buffers as one datagram
	* \return true If data were sent
	*
	* \param to Destination IpAddress (must match socket protocol)
	* \param buffers A pointer to an array of NetBuffer containing buffers and size data
	* \param size Number of NetBuffer to send
	* \param sent Optional argument to get the number of bytes sent
	*/
	bool UdpSocket::SendMultiple(const IpAddress& to, const NetBuffer* buffers, std::size_t bufferCount, std::size_t* sent)
	{
		NazaraAssert(to.IsValid(), "Invalid ip address");
		NazaraAssert(to.GetProtocol() == m_protocol, "IP Address has a different protocol than the socket");
		NazaraAssert(buffers && bufferCount > 0, "Invalid buffer");

		int byteSent;
		if (!SocketImpl::SendMultiple(m_handle, buffers, bufferCount, to, &byteSent, &m_lastError))
			return false;

		if (sent)
			*sent = byteSent;

		return true;
	}
开发者ID:DigitalPulseSoftware,项目名称:NazaraEngine,代码行数:24,代码来源:UdpSocket.cpp

示例6: Send

	bool UdpSocket::Send(const IpAddress& to, const void* buffer, std::size_t size, std::size_t* sent)
	{
		NazaraAssert(to.IsValid(), "Invalid ip address");
		NazaraAssert(to.GetProtocol() == m_protocol, "IP Address has a different protocol than the socket");
		NazaraAssert(buffer && size > 0, "Invalid buffer");

		int byteSent;
		if (!SocketImpl::SendTo(m_handle, buffer, static_cast<int>(size), to, &byteSent, &m_lastError))
			return false;

		if (sent)
			*sent = byteSent;

		return true;
	}
开发者ID:DigitalPulseSoftware,项目名称:NazaraEngine,代码行数:15,代码来源:UdpSocket.cpp

示例7: Connect

	SocketState SocketImpl::Connect(SocketHandle handle, const IpAddress& address, SocketError* error)
	{
		NazaraAssert(handle != InvalidHandle, "Invalid handle");
		NazaraAssert(address.IsValid(), "Invalid address");

		IpAddressImpl::SockAddrBuffer nameBuffer;
		int bufferLength = IpAddressImpl::ToSockAddr(address, nameBuffer.data());

		if (error)
			*error = SocketError_NoError;

		// Clear socket error status
		ClearErrorCode(handle);

		if (connect(handle, reinterpret_cast<const sockaddr*>(nameBuffer.data()), bufferLength) == SOCKET_ERROR)
		{
			int errorCode = WSAGetLastError();
			switch (errorCode) //< Check for "normal errors" first
			{
				case WSAEALREADY:
				case WSAEWOULDBLOCK:
					return SocketState_Connecting;

				case WSAEISCONN:
					return SocketState_Connected;
			}

			if (error)
			{
				if (errorCode == WSAEADDRNOTAVAIL)
					*error = SocketError_ConnectionRefused; //< ConnectionRefused seems more legit than AddressNotAvailable in connect case
				else
					*error = TranslateWSAErrorToSocketError(errorCode);
			}

			return SocketState_NotConnected;
		}

		return SocketState_Connected;
	}
开发者ID:,项目名称:,代码行数:40,代码来源:

示例8: Connect

	SocketState TcpClient::Connect(const IpAddress& remoteAddress)
	{
		NazaraAssert(remoteAddress.IsValid(), "Invalid remote address");
		NazaraAssert(remoteAddress.GetPort() != 0, "Remote address has no port");

		Disconnect();
		Open(remoteAddress.GetProtocol());

		CallOnExit restoreBlocking;
		if (m_isBlockingEnabled)
		{
			SocketImpl::SetBlocking(m_handle, false);
			restoreBlocking.Reset([this] ()
			{
				SocketImpl::SetBlocking(m_handle, true);
			});
		}

		SocketState state = SocketImpl::Connect(m_handle, remoteAddress, &m_lastError);
		m_peerAddress = (state != SocketState_NotConnected) ? remoteAddress : IpAddress::Invalid;

		UpdateState(state);
		return state;
	}
开发者ID:Ardakaniz,项目名称:NazaraEngine,代码行数:24,代码来源:TcpClient.cpp


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