mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 01:26:50 -04:00
3DS: Log when polling socket write fails
Wii/GameCube: Give better error codes for when gethostbyname fails, instead of just returning 'invalid argument'
This commit is contained in:
parent
8a84095ee8
commit
8b53b9eb9d
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user