Skip to content

Commit

Permalink
Fix consecutive connect on the same socket on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
RipleyTom committed Jun 9, 2023
1 parent 6aff280 commit 51bf5ba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 7 additions & 1 deletion rpcs3/Emu/Cell/lv2/sys_net/lv2_socket_native.cpp
Expand Up @@ -216,7 +216,13 @@ std::optional<s32> lv2_socket_native::connect(const sys_net_sockaddr& addr)
return CELL_OK;
}

sys_net_error result = get_last_error(!so_nbio);
sys_net_error result;

#ifdef _WIN32
result = get_last_error(!so_nbio, connecting);
#else
result = get_last_error(!so_nbio);
#endif

if (result)
{
Expand Down
15 changes: 12 additions & 3 deletions rpcs3/Emu/Cell/lv2/sys_net/sys_net_helpers.cpp
Expand Up @@ -88,10 +88,19 @@ 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;
}

// Windows will return SYS_NET_EINVAL when using connect on a non-blocking socket that is already attempting a connection
if (result == SYS_NET_EINVAL)
{
return SYS_NET_EALREADY;
}
}
#endif

Expand Down

0 comments on commit 51bf5ba

Please sign in to comment.