net_socket: getpeername: IsConnected() when parent is not set

this fixes a test in libuv

Change-Id: I3002f9c44794ff3f8215ebc000fefa0f90b80279
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6455
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
This commit is contained in:
Jérôme Duval 2023-05-14 14:46:18 +02:00 committed by waddlesplash
parent 9c1af36c30
commit fc13358aca

View File

@ -1050,7 +1050,11 @@ socket_getpeername(net_socket* _socket, struct sockaddr* address,
socklen_t* _addressLength) socklen_t* _addressLength)
{ {
net_socket_private* socket = (net_socket_private*)_socket; net_socket_private* socket = (net_socket_private*)_socket;
if (!socket->is_connected || socket->peer.ss_len == 0) BReference<net_socket_private> parent;
if (socket->parent.PrivatePointer() != NULL)
parent = socket->parent.GetReference();
if ((!parent.IsSet() && !socket->is_connected) || socket->peer.ss_len == 0)
return ENOTCONN; return ENOTCONN;
memcpy(address, &socket->peer, min_c(*_addressLength, socket->peer.ss_len)); memcpy(address, &socket->peer, min_c(*_addressLength, socket->peer.ss_len));