From f0179b5be669191ab0a9da8c53fe5e2df9672921 Mon Sep 17 00:00:00 2001 From: Gauvain 'GovanifY' Roussel-Tarbouriech Date: Sun, 30 Aug 2020 11:46:29 +0200 Subject: [PATCH] IPC: reply datagram splittage --- pcsx2/IPC.cpp | 28 +++++++++++++++------------- pcsx2/IPC.h | 5 +++-- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/pcsx2/IPC.cpp b/pcsx2/IPC.cpp index d8204e2bcb..6fc4c6d4a5 100644 --- a/pcsx2/IPC.cpp +++ b/pcsx2/IPC.cpp @@ -141,21 +141,21 @@ void SocketIPC::ExecuteTaskInThread() #ifdef _WIN32 // socket timeout - DWORD timeout = 10 * 1000; // 10 seconds - setsockopt(m_msgsock, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof timeout); + DWORD tv = 10 * 1000; // 10 seconds #else // socket timeout struct timeval tv; tv.tv_sec = 10; tv.tv_usec = 0; - setsockopt(m_msgsock, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv, sizeof tv); #endif + setsockopt(m_msgsock, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv, sizeof tv); + setsockopt(m_msgsock, SOL_SOCKET, SO_SNDTIMEO, (const char*)&tv, sizeof tv); // either int or ssize_t depending on the platform, so we have to // use a bunch of auto auto receive_length = read_portable(m_msgsock, m_ipc_buffer, MAX_IPC_SIZE); - if (receive_length >= 0) + if (receive_length > 0) { // if we already received at least the length then we read it auto end_length = 4; @@ -227,15 +227,17 @@ SocketIPC::~SocketIPC() DESTRUCTOR_CATCHALL } -char* SocketIPC::MakeOkIPC(char* ret_buffer) +char* SocketIPC::MakeOkIPC(char* ret_buffer, uint32_t size = 5) { - ret_buffer[0] = IPC_OK; + ToArray(ret_buffer, size, 0); + ret_buffer[4] = IPC_OK; return ret_buffer; } -char* SocketIPC::MakeFailIPC(char* ret_buffer) +char* SocketIPC::MakeFailIPC(char* ret_buffer, uint32_t size = 5) { - ret_buffer[0] = IPC_FAIL; + ToArray(ret_buffer, size, 0); + ret_buffer[4] = IPC_FAIL; return ret_buffer; } @@ -244,9 +246,9 @@ SocketIPC::IPCBuffer SocketIPC::ParseCommand(char* buf, char* ret_buffer, u32 bu // currently all our instructions require a running VM so we check once // here, slightly helps performance if (!m_vm->HasActiveMachine()) - return IPCBuffer{1, MakeFailIPC(ret_buffer)}; + return IPCBuffer{5, MakeFailIPC(ret_buffer)}; - u32 ret_cnt = 1; + u32 ret_cnt = 5; u32 buf_cnt = 0; while (buf_cnt < buf_size) @@ -254,7 +256,7 @@ SocketIPC::IPCBuffer SocketIPC::ParseCommand(char* buf, char* ret_buffer, u32 bu // if we haven't received enough byte for the address used in R/W // commands and opcode, changeme when address is out of the header! if (!SafetyChecks(buf_cnt, 4 + 1, ret_cnt, 0, buf_size)) - return IPCBuffer{1, MakeFailIPC(ret_buffer)}; + return IPCBuffer{5, MakeFailIPC(ret_buffer)}; // YY YY YY YY from schema below // curently always used by implemented commands so it is out of the @@ -351,9 +353,9 @@ SocketIPC::IPCBuffer SocketIPC::ParseCommand(char* buf, char* ret_buffer, u32 bu default: { error: - return IPCBuffer{1, MakeFailIPC(ret_buffer)}; + return IPCBuffer{5, MakeFailIPC(ret_buffer)}; } } } - return IPCBuffer{(int)ret_cnt, MakeOkIPC(ret_buffer)}; + return IPCBuffer{(int)ret_cnt, MakeOkIPC(ret_buffer, ret_cnt)}; } diff --git a/pcsx2/IPC.h b/pcsx2/IPC.h index 4a8cf1107e..2a01e5819c 100644 --- a/pcsx2/IPC.h +++ b/pcsx2/IPC.h @@ -130,10 +130,11 @@ protected: /* Formats an IPC buffer * ret_buffer: return buffer to use. + * size: size of the IPC buffer. * return value: buffer containing the status code allocated of size * size */ - static inline char* MakeOkIPC(char* ret_buffer); - static inline char* MakeFailIPC(char* ret_buffer); + static inline char* MakeOkIPC(char* ret_buffer, uint32_t size); + static inline char* MakeFailIPC(char* ret_buffer, uint32_t size); /* Converts an uint to an char* in little endian * res_array: the array to modify