mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-07-01 07:15:39 +00:00
Improve 3DS Reliability (#87)
- Simplifies thread priority setup - Sets a max socket buffer size of 0x20000 for the 3DS - Fixes a bug with polling timeouts taking longer than intended - Removes 3DS global socket definition
This commit is contained in:
parent
0f3fa30f62
commit
35f730fedd
@ -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);
|
||||
thread->thread = threadCreate(ThreadProc,
|
||||
ctx,
|
||||
|
@ -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)
|
||||
@ -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
|
||||
@ -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.
|
||||
@ -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) {
|
||||
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user