Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve 3DS Reliability #87

Merged
merged 2 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ int PltCreateThread(const char* name, ThreadEntry entry, void* context, PLT_THRE
OSResumeThread(&thread->thread);
#elif defined(__3DS__)
{
size_t stack_size = 0x40000;
s32 priority = 0x30;
size_t stack_size = 1024 * 1024;
svcGetThreadPriority(&priority, CUR_THREAD_HANDLE);
cgutman marked this conversation as resolved.
Show resolved Hide resolved
thread->thread = threadCreate(ThreadProc,
ctx,
Expand Down
15 changes: 10 additions & 5 deletions src/PlatformSockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ DWORD (WINAPI *pfnWlanSetInterface)(HANDLE hClientHandle, CONST GUID *pInterface

#ifdef __3DS__
in_port_t n3ds_udp_port = 47998;
static const int n3ds_max_buf_size = 0x20000;
#endif

void addrToUrlSafeString(struct sockaddr_storage* addr, char* string, size_t stringLength)
Expand Down Expand Up @@ -149,11 +150,13 @@ int pollSockets(struct pollfd* pollFds, int pollFdsCount, int timeoutMs) {
return err;
#elif defined(__3DS__)
int err;
for (int i = 0; i < timeoutMs; i++) {
err = poll(pollFds, pollFdsCount, 1); // need to do this on 3ds since poll will block even if socket is ready before
u64 poll_start = osGetTime();
for (u64 i = poll_start; (i - poll_start) < timeoutMs; i = osGetTime()) {
err = poll(pollFds, pollFdsCount, 0); // This is running for 14ms
if (err) {
break;
}
svcSleepThread(1000);
}
return err;
#else
Expand Down Expand Up @@ -348,6 +351,10 @@ SOCKET bindUdpSocket(int addressFamily, struct sockaddr_storage* localAddr, SOCK
setSocketQos(s, socketQosType);
}

#ifdef __3DS__
if (bufferSize == 0 || bufferSize > n3ds_max_buf_size)
bufferSize = n3ds_max_buf_size;
#endif
if (bufferSize != 0) {
// We start at the requested recv buffer value and step down until we find
// a value that the OS will accept.
Expand All @@ -359,6 +366,7 @@ SOCKET bindUdpSocket(int addressFamily, struct sockaddr_storage* localAddr, SOCK
}
else if (bufferSize <= RCV_BUFFER_SIZE_MIN) {
// Failed to set a buffer size within the allowable range
Limelog("Set rcv buffer size failed: %d\n", LastSocketError());
break;
}
else if (bufferSize - RCV_BUFFER_SIZE_STEP <= RCV_BUFFER_SIZE_MIN) {
Expand Down Expand Up @@ -425,9 +433,6 @@ SOCKET createSocket(int addressFamily, int socketType, int protocol, bool nonBlo
setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, (char*)&val, sizeof(val));
}
#endif
#ifdef __3DS__
SOCU_AddGlobalSocket(s);
#endif

if (nonBlocking) {
setSocketNonBlocking(s, true);
Expand Down
Loading