From 54a38aa927644f274c78c59c93c37662ae3f9e65 Mon Sep 17 00:00:00 2001 From: Zion Nimchuk Date: Thu, 22 Jun 2017 12:08:17 -0700 Subject: [PATCH] Fix issue #2788 --- rpcs3/Emu/Cell/Modules/sys_net.cpp | 43 +++++++++++++++++++++++------- rpcs3/Emu/Cell/Modules/sys_net.h | 3 +++ 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/sys_net.cpp b/rpcs3/Emu/Cell/Modules/sys_net.cpp index e7a44ead4a..61dad0d646 100644 --- a/rpcs3/Emu/Cell/Modules/sys_net.cpp +++ b/rpcs3/Emu/Cell/Modules/sys_net.cpp @@ -16,7 +16,6 @@ #include #include #endif - #include logs::channel libnet("libnet"); @@ -567,7 +566,7 @@ namespace sys_net return -1; } - if (level != SOL_SOCKET && level != IPPROTO_TCP) + if (level != PS3_SOL_SOCKET && level != IPPROTO_TCP) { fmt::throw_exception("Invalid socket option level!" HERE); } @@ -575,7 +574,7 @@ namespace sys_net s32 ret; #ifdef _WIN32 - if (level == SOL_SOCKET) + if (level == PS3_SOL_SOCKET) { switch (optname) { @@ -623,12 +622,14 @@ namespace sys_net } case OP_SO_USECRYPTO: { - libnet.warning("Socket option OP_SO_USECRYPTO is unimplemented"); + libnet.todo("Socket option OP_SO_USECRYPTO is unimplemented"); + ret = CELL_OK; break; } case OP_SO_USESIGNATURE: { - libnet.warning("Socket option OP_SO_USESIGNATURE is unimplemented"); + libnet.todo("Socket option OP_SO_USESIGNATURE is unimplemented"); + ret = CELL_OK; break; } case OP_SO_BROADCAST: @@ -669,7 +670,7 @@ namespace sys_net } } #else - if (level == SOL_SOCKET) + if (level == PS3_SOL_SOCKET) { switch (optname) { @@ -690,6 +691,24 @@ namespace sys_net ret = fcntl(sock->s, F_SETFL, flags); break; } + case OP_SO_RCVBUF: + { + u32 recvbuff = *(u32*)optval.get_ptr(); + ret = ::setsockopt(sock->s, SOL_SOCKET, SO_RCVBUF, (const char*)&recvbuff, sizeof(recvbuff)); + break; + } + case OP_SO_USECRYPTO: + { + libnet.warning("Socket option OP_SO_USECRYPTO is unimplemented"); + ret = CELL_OK; + break; + } + case OP_SO_USESIGNATURE: + { + libnet.warning("Socket option OP_SO_USESIGNATURE is unimplemented"); + ret = CELL_OK; + break; + } default: libnet.error("Unknown socket option for Unix: 0x%x", optname); @@ -821,8 +840,8 @@ namespace sys_net s32 socketselect(s32 nfds, vm::ptr readfds, vm::ptr writefds, vm::ptr exceptfds, vm::ptr timeout) { - libnet.warning("socketselect(nfds=%d, readfds=*0x%x, writefds=*0x%x, exceptfds=*0x%x, timeout=*0x%x)", nfds, readfds, writefds, exceptfds, timeout); - + libnet.warning("socketselect(nfds=%d, readfds=*0x%x, writefds=*0x%x, exceptfds=*0x%x, timeout.tv_sec=%d, timeout.tv_usec=%d)", + nfds, readfds, writefds, exceptfds, timeout->tv_sec, timeout->tv_usec); ::timeval _timeout; if (timeout) @@ -830,8 +849,12 @@ namespace sys_net _timeout.tv_sec = timeout->tv_sec; _timeout.tv_usec = timeout->tv_usec; } - - //libnet.error("timeval: %d . %d", _timeout.tv_sec, _timeout.tv_usec); + + if (_timeout.tv_usec >= 1000000) + { + _timeout.tv_sec = _timeout.tv_sec ? _timeout.tv_sec - 1 : _timeout.tv_sec + 1; + _timeout.tv_usec = 0; + } ::fd_set _readfds; ::fd_set _writefds; diff --git a/rpcs3/Emu/Cell/Modules/sys_net.h b/rpcs3/Emu/Cell/Modules/sys_net.h index cc48931848..3cbac55b8d 100644 --- a/rpcs3/Emu/Cell/Modules/sys_net.h +++ b/rpcs3/Emu/Cell/Modules/sys_net.h @@ -9,6 +9,9 @@ namespace vm { using namespace ps3; } namespace sys_net { + +// It turns out SOL_SOCKET is equal to 1 on Linux, but 0xffff on Windows, and it appears the PS3 uses 0xffff, like Windows +#define PS3_SOL_SOCKET 0xffff // Error codes enum {