mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-07-02 15:56:02 +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);
|
OSResumeThread(&thread->thread);
|
||||||
#elif defined(__3DS__)
|
#elif defined(__3DS__)
|
||||||
{
|
{
|
||||||
|
size_t stack_size = 0x40000;
|
||||||
s32 priority = 0x30;
|
s32 priority = 0x30;
|
||||||
size_t stack_size = 1024 * 1024;
|
|
||||||
svcGetThreadPriority(&priority, CUR_THREAD_HANDLE);
|
svcGetThreadPriority(&priority, CUR_THREAD_HANDLE);
|
||||||
thread->thread = threadCreate(ThreadProc,
|
thread->thread = threadCreate(ThreadProc,
|
||||||
ctx,
|
ctx,
|
||||||
|
@ -37,6 +37,7 @@ DWORD (WINAPI *pfnWlanSetInterface)(HANDLE hClientHandle, CONST GUID *pInterface
|
|||||||
|
|
||||||
#ifdef __3DS__
|
#ifdef __3DS__
|
||||||
in_port_t n3ds_udp_port = 47998;
|
in_port_t n3ds_udp_port = 47998;
|
||||||
|
static const int n3ds_max_buf_size = 0x20000;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void addrToUrlSafeString(struct sockaddr_storage* addr, char* string, size_t stringLength)
|
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;
|
return err;
|
||||||
#elif defined(__3DS__)
|
#elif defined(__3DS__)
|
||||||
int err;
|
int err;
|
||||||
for (int i = 0; i < timeoutMs; i++) {
|
u64 poll_start = osGetTime();
|
||||||
err = poll(pollFds, pollFdsCount, 1); // need to do this on 3ds since poll will block even if socket is ready before
|
for (u64 i = poll_start; (i - poll_start) < timeoutMs; i = osGetTime()) {
|
||||||
|
err = poll(pollFds, pollFdsCount, 0); // This is running for 14ms
|
||||||
if (err) {
|
if (err) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
svcSleepThread(1000);
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
#else
|
#else
|
||||||
@ -348,6 +351,10 @@ SOCKET bindUdpSocket(int addressFamily, struct sockaddr_storage* localAddr, SOCK
|
|||||||
setSocketQos(s, socketQosType);
|
setSocketQos(s, socketQosType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __3DS__
|
||||||
|
if (bufferSize == 0 || bufferSize > n3ds_max_buf_size)
|
||||||
|
bufferSize = n3ds_max_buf_size;
|
||||||
|
#endif
|
||||||
if (bufferSize != 0) {
|
if (bufferSize != 0) {
|
||||||
// We start at the requested recv buffer value and step down until we find
|
// We start at the requested recv buffer value and step down until we find
|
||||||
// a value that the OS will accept.
|
// 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) {
|
else if (bufferSize <= RCV_BUFFER_SIZE_MIN) {
|
||||||
// Failed to set a buffer size within the allowable range
|
// Failed to set a buffer size within the allowable range
|
||||||
|
Limelog("Set rcv buffer size failed: %d\n", LastSocketError());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (bufferSize - RCV_BUFFER_SIZE_STEP <= RCV_BUFFER_SIZE_MIN) {
|
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));
|
setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, (char*)&val, sizeof(val));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef __3DS__
|
|
||||||
SOCU_AddGlobalSocket(s);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (nonBlocking) {
|
if (nonBlocking) {
|
||||||
setSocketNonBlocking(s, true);
|
setSocketNonBlocking(s, true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user