本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}