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


C++ SocketName::from_sockaddr方法代码示例

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


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

示例1: read

	int UDPSocketImpl::read(void *data, int size, SocketName &endpoint)
	{
		sockaddr_in addr;
		int addr_len = sizeof(sockaddr_in);

		int result = recvfrom(handle, static_cast<char*>(data), size, 0, (sockaddr *)&addr, &addr_len);
		if (result == SOCKET_ERROR)
		{
			int last_error = WSAGetLastError();
			// To do: maybe return different return values for sending errors
			if (last_error == WSAEWOULDBLOCK || last_error == WSAEMSGSIZE || last_error == WSAECONNRESET || last_error == WSAENETRESET)
			{
				endpoint = SocketName();
				return -1;
			}
			else
			{
				throw Exception("Error reading from udp socket");
			}
		}

		endpoint = SocketName();
		endpoint.from_sockaddr(AF_INET, (sockaddr *)&addr, addr_len);
		return result;
	}
开发者ID:rombust,项目名称:UICore,代码行数:25,代码来源:udp_socket.cpp

示例2: sizeof

int Win32Socket::peek_from(void *data, int size, SocketName &out_socketname)
{
	sockaddr_in new_addr;
	memset(&new_addr, 0, sizeof(sockaddr_in));
	int addr_size = sizeof(sockaddr_in);
	int result = ::recvfrom(handle, (char *) data, size, MSG_PEEK, (sockaddr *) &new_addr, &addr_size);
	throw_if_failed(result);
	out_socketname.from_sockaddr(AF_INET, (sockaddr *) &new_addr, size);
	reset_receive();
	return result;
}
开发者ID:Cassie90,项目名称:ClanLib,代码行数:11,代码来源:win32_socket.cpp

示例3: remote_name

	SocketName TCPConnectionImpl::remote_name()
	{
		sockaddr_in addr;
		memset(&addr, 0, sizeof(sockaddr_in));
		int size = sizeof(sockaddr_in);
		int result = getpeername(handle, (sockaddr *)&addr, &size);
		if (result == SOCKET_ERROR)
			throw Exception("Error retrieving remote socket name");

		SocketName name;
		name.from_sockaddr(AF_INET, (sockaddr *)&addr, sizeof(sockaddr_in));
		return name;
	}
开发者ID:rombust,项目名称:UICore,代码行数:13,代码来源:tcp_connection.cpp

示例4: local_name

	SocketName TCPConnectionImpl::local_name()
	{
		sockaddr_in addr;
		memset(&addr, 0, sizeof(sockaddr_in));
		socklen_t size = sizeof(sockaddr_in);
		int result = getsockname(handle, (sockaddr *)&addr, &size);
		if (result == -1)
			throw Exception("Error retrieving local socket name");

		SocketName name;
		name.from_sockaddr(AF_INET, (sockaddr *)&addr, sizeof(sockaddr_in));
		return name;
	}
开发者ID:rombust,项目名称:UICore,代码行数:13,代码来源:tcp_connection.cpp

示例5: accept

	TCPConnection TCPListen::accept(SocketName &out_end_point)
	{
		sockaddr_in peer_address = { 0 };
		socklen_t peer_address_length = sizeof(sockaddr_in);

		int result = ::accept(impl->handle, reinterpret_cast<sockaddr*>(&peer_address), &peer_address_length);
		if (result == -1)
		{
			if (errno == EWOULDBLOCK)
				return TCPConnection();
			else
				throw Exception("Error accepting from socket");
		}

		out_end_point.from_sockaddr(AF_INET, reinterpret_cast<sockaddr*>(&peer_address), peer_address_length);
		return TCPConnection(std::make_shared<TCPSocket>(result));
	}
开发者ID:ARMCoderCHS,项目名称:ClanLib,代码行数:17,代码来源:tcp_listen.cpp


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