From e5a02cebb452e27eb53f5bfd643fbae38de00ce1 Mon Sep 17 00:00:00 2001 From: ANR2ME Date: Sun, 18 Oct 2020 06:32:41 +0700 Subject: [PATCH] Added Connection Refused error code on PtpConnect --- Core/HLE/proAdhoc.h | 2 ++ Core/HLE/sceNetAdhoc.cpp | 35 +++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Core/HLE/proAdhoc.h b/Core/HLE/proAdhoc.h index 30eda1ebe4..9edc7d89e2 100644 --- a/Core/HLE/proAdhoc.h +++ b/Core/HLE/proAdhoc.h @@ -59,6 +59,7 @@ #undef ESHUTDOWN #undef ECONNABORTED #undef ECONNRESET +#undef ECONNREFUSED #undef ENOTCONN #undef EAGAIN #undef EINPROGRESS @@ -69,6 +70,7 @@ #define ESHUTDOWN WSAESHUTDOWN #define ECONNABORTED WSAECONNABORTED #define ECONNRESET WSAECONNRESET +#define ECONNREFUSED WSAECONNREFUSED #define ENOTCONN WSAENOTCONN #define EAGAIN WSAEWOULDBLOCK #define EINPROGRESS WSAEWOULDBLOCK diff --git a/Core/HLE/sceNetAdhoc.cpp b/Core/HLE/sceNetAdhoc.cpp index 316c9649be..5cbd4e8020 100644 --- a/Core/HLE/sceNetAdhoc.cpp +++ b/Core/HLE/sceNetAdhoc.cpp @@ -3308,21 +3308,28 @@ static int sceNetAdhocPtpConnect(int id, int timeout, int flag) { return 0; } - // Connection in Progress - else if (connectresult == SOCKET_ERROR && connectInProgress(errorcode)) { - socket->data.ptp.state = ADHOC_PTP_STATE_SYN_SENT; - socket->attemptCount++; - socket->lastAttempt = CoreTiming::GetGlobalTimeUsScaled(); - // Blocking Mode - // Workaround: Forcing first attempt to be blocking to prevent issue related to lobby or high latency networks. (can be useful for GvG Next Plus, Dissidia 012, and Fate Unlimited Codes) - if (!flag || (g_Config.bForcedFirstConnect && socket->attemptCount == 1)) { - // Simulate blocking behaviour with non-blocking socket - u64 threadSocketId = ((u64)__KernelGetCurThread()) << 32 | ptpsocket.id; - return WaitBlockingAdhocSocket(threadSocketId, PTP_CONNECT, id, nullptr, nullptr, (flag) ? std::max((int)socket->retry_interval, timeout) : timeout, nullptr, nullptr, "ptp connect"); + // Error handling + else if (connectresult == SOCKET_ERROR) { + // Connection in Progress + if (connectInProgress(errorcode)) { + socket->data.ptp.state = ADHOC_PTP_STATE_SYN_SENT; + socket->attemptCount++; + socket->lastAttempt = CoreTiming::GetGlobalTimeUsScaled(); + // Blocking Mode + // Workaround: Forcing first attempt to be blocking to prevent issue related to lobby or high latency networks. (can be useful for GvG Next Plus, Dissidia 012, and Fate Unlimited Codes) + if (!flag || (g_Config.bForcedFirstConnect && socket->attemptCount == 1)) { + // Simulate blocking behaviour with non-blocking socket + u64 threadSocketId = ((u64)__KernelGetCurThread()) << 32 | ptpsocket.id; + return WaitBlockingAdhocSocket(threadSocketId, PTP_CONNECT, id, nullptr, nullptr, (flag) ? std::max((int)socket->retry_interval, timeout) : timeout, nullptr, nullptr, "ptp connect"); + } + // NonBlocking Mode + else { + return hleLogDebug(SCENET, ERROR_NET_ADHOC_WOULD_BLOCK, "would block"); + } } - // NonBlocking Mode - else { - return hleLogDebug(SCENET, ERROR_NET_ADHOC_WOULD_BLOCK, "would block"); + // No connection could be made because the target device actively refused it. + else if (errorcode == ECONNREFUSED) { + return hleLogError(SCENET, ERROR_NET_ADHOC_CONNECTION_REFUSED, "connection refused"); } } }