Fix EINVAL returned on connect call to connecting socket

This commit is contained in:
RipleyTom 2023-06-10 16:35:14 +02:00 committed by Megamouse
parent c0e97b4e96
commit 5d7e75c5d8
3 changed files with 18 additions and 5 deletions

View file

@ -211,12 +211,20 @@ std::optional<s32> lv2_socket_native::connect(const sys_net_sockaddr& addr)
dnshook.add_dns_spy(lv2_id);
}
#ifdef _WIN32
bool was_connecting = connecting;
#endif
if (::connect(socket, reinterpret_cast<struct sockaddr*>(&native_addr), native_addr_len) == 0)
{
return CELL_OK;
}
#ifdef _WIN32
sys_net_error result = get_last_error(!so_nbio, was_connecting);
#else
sys_net_error result = get_last_error(!so_nbio);
#endif
if (result)
{

View file

@ -201,8 +201,8 @@ void network_thread::operator()()
fds[i].revents = 0;
#ifdef _WIN32
const auto cur_connecting = socklist[i]->is_connecting();
was_connecting[i] = connecting;
connecting[i] = connecting;
was_connecting[i] = cur_connecting;
connecting[i] = cur_connecting;
#endif
}
}

View file

@ -88,10 +88,15 @@ sys_net_error convert_error(bool is_blocking, int native_error, [[maybe_unused]]
}
#ifdef _WIN32
// Windows will return SYS_NET_ENOTCONN when recvfrom/sendto is called on a socket that is connecting but not yet connected
if (is_connecting && result == SYS_NET_ENOTCONN)
if (is_connecting)
{
return SYS_NET_EAGAIN;
// Windows will return SYS_NET_ENOTCONN when recvfrom/sendto is called on a socket that is connecting but not yet connected
if (result == SYS_NET_ENOTCONN)
return SYS_NET_EAGAIN;
// See https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-connect
if (result == SYS_NET_EINVAL || result == SYS_NET_EWOULDBLOCK)
return SYS_NET_EALREADY;
}
#endif