From f8ea50caae9df7ac2954c9941516b2fdc5338a93 Mon Sep 17 00:00:00 2001 From: RipleyTom Date: Sun, 10 Apr 2022 07:42:25 +0200 Subject: [PATCH] sys_net: Fix return values being tagged as errors --- rpcs3/Emu/Cell/lv2/sys_net.cpp | 63 ++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/rpcs3/Emu/Cell/lv2/sys_net.cpp b/rpcs3/Emu/Cell/lv2/sys_net.cpp index 118a1808c7..1aff8d78b0 100644 --- a/rpcs3/Emu/Cell/lv2/sys_net.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_net.cpp @@ -457,7 +457,12 @@ error_code sys_net_bnet_connect(ppu_thread& ppu, s32 s, vm::ptr(s, [&](lv2_socket& sock) -> sys_net_error + const auto sock = idm::check(s, [&](lv2_socket& sock) -> s32 { auto [res, sn_addr] = sock.getpeername(); @@ -513,7 +523,7 @@ error_code sys_net_bnet_getpeername(ppu_thread& ppu, s32 s, vm::ptr(s, [&](lv2_socket& sock) -> sys_net_error + const auto sock = idm::check(s, [&](lv2_socket& sock) -> s32 { if (len < sizeof(s32)) { @@ -614,7 +624,7 @@ error_code sys_net_bnet_getsockopt(ppu_thread& ppu, s32 s, s32 level, s32 optnam *optlen = out_len; } - return static_cast(res); + return res; }); if (!sock) @@ -622,7 +632,12 @@ error_code sys_net_bnet_getsockopt(ppu_thread& ppu, s32 s, s32 level, s32 optnam return -SYS_NET_EBADF; } - return sock.ret; + if (sock.ret < 0) + { + return sys_net_error{sock.ret}; + } + + return CELL_OK; } error_code sys_net_bnet_listen(ppu_thread& ppu, s32 s, s32 backlog) @@ -636,9 +651,9 @@ error_code sys_net_bnet_listen(ppu_thread& ppu, s32 s, s32 backlog) return -SYS_NET_EINVAL; } - const auto sock = idm::check(s, [&](lv2_socket& sock) -> sys_net_error + const auto sock = idm::check(s, [&](lv2_socket& sock) -> s32 { - return static_cast(sock.listen(backlog)); + return sock.listen(backlog); }); if (!sock) @@ -646,9 +661,9 @@ error_code sys_net_bnet_listen(ppu_thread& ppu, s32 s, s32 backlog) return -SYS_NET_EBADF; } - if (sock.ret) + if (sock.ret < 0) { - return sock.ret; + return sys_net_error{sock.ret}; } return CELL_OK; @@ -759,7 +774,7 @@ error_code sys_net_bnet_recvfrom(ppu_thread& ppu, s32 s, vm::ptr buf, u32 return not_an_error(result); } - if (result > 0) + if (result >= 0) { if (addr) { @@ -770,7 +785,7 @@ error_code sys_net_bnet_recvfrom(ppu_thread& ppu, s32 s, vm::ptr buf, u32 return not_an_error(result); } - return result; + return sys_net_error{result}; } error_code sys_net_bnet_recvmsg(ppu_thread& ppu, s32 s, vm::ptr msg, s32 flags) @@ -870,10 +885,11 @@ error_code sys_net_bnet_sendto(ppu_thread& ppu, s32 s, vm::cptr buf, u32 l } } - if (result > 0 || result == -SYS_NET_EWOULDBLOCK) + if (result >= 0 || result == -SYS_NET_EWOULDBLOCK) { return not_an_error(result); } + return sys_net_error{result}; } @@ -930,7 +946,12 @@ error_code sys_net_bnet_setsockopt(ppu_thread& ppu, s32 s, s32 level, s32 optnam return -SYS_NET_EBADF; } - return sock.ret; + if (sock.ret < 0) + { + return sys_net_error{sock.ret}; + } + + return not_an_error(sock.ret); } error_code sys_net_bnet_shutdown(ppu_thread& ppu, s32 s, s32 how) @@ -954,9 +975,9 @@ error_code sys_net_bnet_shutdown(ppu_thread& ppu, s32 s, s32 how) return -SYS_NET_EBADF; } - if (sock.ret) + if (sock.ret < 0) { - return sock.ret; + return sys_net_error{sock.ret}; } return CELL_OK; @@ -989,7 +1010,7 @@ error_code sys_net_bnet_socket(ppu_thread& ppu, lv2_socket_family family, lv2_so auto lv2_native = std::make_shared(family, type, protocol); if (s32 result = lv2_native->create_socket(); result < 0) { - return result; + return sys_net_error{result}; } sock_lv2 = std::move(lv2_native);