From 8b53b9eb9d242d91cdba9a9ada78e683b7c82a5c Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 17 Aug 2023 20:04:51 +1000 Subject: [PATCH] 3DS: Log when polling socket write fails Wii/GameCube: Give better error codes for when gethostbyname fails, instead of just returning 'invalid argument' --- src/Launcher.c | 3 +-- src/Platform_3DS.c | 5 ++++- src/Platform_GCWii.c | 22 +++++++++++++--------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/Launcher.c b/src/Launcher.c index b4e5990ae..e928d2e23 100644 --- a/src/Launcher.c +++ b/src/Launcher.c @@ -276,10 +276,9 @@ void Launcher_Run(void) { Options_SaveIfChanged(); Launcher_Free(); + Launcher_ShouldExit = false; #ifdef CC_BUILD_MOBILE - /* infinite loop on mobile */ - Launcher_ShouldExit = false; /* Reset components */ Platform_LogConst("undoing components"); Drawer2D_Component.Free(); diff --git a/src/Platform_3DS.c b/src/Platform_3DS.c index 0b878c42c..5f297240d 100644 --- a/src/Platform_3DS.c +++ b/src/Platform_3DS.c @@ -360,6 +360,7 @@ cc_result Socket_Read(cc_socket s, cc_uint8* data, cc_uint32 count, cc_uint32* m cc_result Socket_Write(cc_socket s, const cc_uint8* data, cc_uint32 count, cc_uint32* modified) { int sentCount = send(s, data, count, 0); if (sentCount != -1) { *modified = sentCount; return 0; } + *modified = 0; return errno; } @@ -378,6 +379,7 @@ static cc_result Socket_Poll(cc_socket s, int mode, cc_bool* success) { /* to match select, closed socket still counts as readable */ int flags = mode == SOCKET_POLL_READ ? (POLLIN | POLLHUP) : POLLOUT; *success = (pfd.revents & flags) != 0; + return 0; } @@ -392,6 +394,7 @@ cc_result Socket_CheckWritable(cc_socket s, cc_bool* writable) { /* https://stackoverflow.com/questions/29479953/so-error-value-after-successful-socket-operation */ getsockopt(s, SOL_SOCKET, SO_ERROR, &res, &resultSize); + Platform_LogConst("--write poll failed--"); return res; } @@ -468,4 +471,4 @@ cc_result Platform_Encrypt(const void* data, int len, cc_string* dst) { cc_result Platform_Decrypt(const void* data, int len, cc_string* dst) { return ERR_NOT_SUPPORTED; } -#endif +#endif \ No newline at end of file diff --git a/src/Platform_GCWii.c b/src/Platform_GCWii.c index ddc31e71f..e4cb41032 100644 --- a/src/Platform_GCWii.c +++ b/src/Platform_GCWii.c @@ -368,16 +368,19 @@ union SocketAddress { static int ParseHost(union SocketAddress* addr, const char* host) { #ifdef HW_RVL struct hostent* res = net_gethostbyname(host); + // avoid confusion with SSL error codes + // e.g. FFFF FFF7 > FF00 FFF7 + if (!res) return -0xFF0000 + errno; - if (!res || res->h_addrtype != AF_INET) return false; // Must have at least one IPv4 address - if (!res->h_addr_list[0]) return false; + if (res->h_addrtype != AF_INET) return ERR_INVALID_ARGUMENT; + if (!res->h_addr_list[0]) return ERR_INVALID_ARGUMENT; addr->v4.sin_addr = *(struct in_addr*)res->h_addr_list[0]; - return true; + return 0; #else // DNS resolution not implemented in gamecube libbba - return false; + return ERR_NOT_SUPPORTED; #endif } @@ -385,20 +388,21 @@ static int ParseAddress(union SocketAddress* addr, const cc_string* address) { char str[NATIVE_STR_LEN]; String_EncodeUtf8(str, address); - if (inet_aton(str, &addr->v4.sin_addr) > 0) return true; + if (inet_aton(str, &addr->v4.sin_addr) > 0) return 0; return ParseHost(addr, str); } int Socket_ValidAddress(const cc_string* address) { union SocketAddress addr; - return ParseAddress(&addr, address); + return ParseAddress(&addr, address) == 0; } cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port, cc_bool nonblocking) { union SocketAddress addr; + int res; *s = -1; - if (!ParseAddress(&addr, address)) return ERR_INVALID_ARGUMENT; + if ((res = ParseAddress(&addr, address))) return res; *s = net_socket(AF_INET, SOCK_STREAM, 0); if (*s < 0) return *s; @@ -411,7 +415,7 @@ cc_result Socket_Connect(cc_socket* s, const cc_string* address, int port, cc_bo addr.v4.sin_family = AF_INET; addr.v4.sin_port = htons(port); - int res = net_connect(*s, &addr.raw, sizeof(addr.v4)); + res = net_connect(*s, &addr.raw, sizeof(addr.v4)); return res < 0 ? res : 0; } @@ -592,4 +596,4 @@ cc_result Platform_Encrypt(const void* data, int len, cc_string* dst) { cc_result Platform_Decrypt(const void* data, int len, cc_string* dst) { return ERR_NOT_SUPPORTED; } -#endif +#endif \ No newline at end of file