1
0
mirror of https://github.com/libretro/RetroArch synced 2024-07-03 00:38:44 +00:00

wiiu: Network optimisations - WINSCALE, TCP sACK, large buffers

See code sample in https://github.com/devkitPro/wut/issues/169 and 
2430789406/src/net.c (L88)
This commit is contained in:
Ash Logan 2021-07-18 13:56:22 +10:00
parent 6521bfcdc1
commit e5553bde4e
6 changed files with 64 additions and 1 deletions

View File

@ -158,6 +158,11 @@ static INLINE bool isagain(int bytes)
#endif
}
#ifdef WIIU
#define WIIU_RCVBUF (128 * 2 * 1024)
#define WIIU_SNDBUF (128 * 2 * 1024)
#endif
#ifdef _XBOX
#define socklen_t int

View File

@ -264,6 +264,25 @@ void freeaddrinfo_retro(struct addrinfo *res)
#endif
}
#if defined(WIIU)
#include <malloc.h>
static OSThread wiiu_net_cmpt_thread;
static void wiiu_net_cmpt_thread_cleanup(OSThread *thread, void *stack) {
free(stack);
}
static int wiiu_net_cmpt_thread_entry(int argc, const char** argv) {
const int buf_size = WIIU_RCVBUF + WIIU_SNDBUF;
void* buf = memalign(128, buf_size);
if (!buf) return -1;
somemopt(1, buf, buf_size, 0);
free(buf);
return 0;
}
#endif
/**
* network_init:
*
@ -332,6 +351,18 @@ bool network_init(void)
return false;
#elif defined(WIIU)
socket_lib_init();
const int stack_size = 4096;
void* stack = malloc(stack_size);
if (stack && OSCreateThread(&wiiu_net_cmpt_thread,
wiiu_net_cmpt_thread_entry, 0, NULL, stack+stack_size, stack_size,
3, OS_THREAD_ATTRIB_AFFINITY_ANY)) {
OSSetThreadName(&wiiu_net_cmpt_thread, "Network compat thread");
OSSetThreadDeallocator(&wiiu_net_cmpt_thread,
wiiu_net_cmpt_thread_cleanup);
OSResumeThread(&wiiu_net_cmpt_thread);
}
#elif defined(_3DS)
_net_compat_net_memory = (u32*)memalign(SOC_ALIGN, SOC_BUFFERSIZE);
if (!_net_compat_net_memory)

View File

@ -256,6 +256,20 @@ int socket_connect(int fd, void *data, bool timeout_enable)
setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (char*)&timeout, sizeof timeout);
}
#endif
#if defined(WIIU)
int op = 1;
setsockopt(fd, SOL_SOCKET, SO_WINSCALE, &op, sizeof(op));
if (addr->ai_socktype == SOCK_STREAM) {
setsockopt(fd, SOL_SOCKET, SO_TCPSACK, &op, sizeof(op));
setsockopt(fd, SOL_SOCKET, 0x10000, &op, sizeof(op));
int recvsz = WIIU_RCVBUF;
setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &recvsz, sizeof(recvsz));
int sendsz = WIIU_SNDBUF;
setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &sendsz, sizeof(sendsz));
}
#endif
return connect(fd, addr->ai_addr, addr->ai_addrlen);

View File

@ -21,6 +21,10 @@ extern "C" {
/* #define MSG_DONTWAIT 0x0004 */
#define SO_REUSEADDR 0x0004
#define SO_WINSCALE 0x0400
#define SO_TCPSACK 0x0200
#define SO_SNDBUF 0x1001
#define SO_RCVBUF 0x1002
#define SO_NBIO 0x1014
#define SO_NONBLOCK 0x1016
@ -70,6 +74,7 @@ int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t
int shutdown(int sockfd, int how);
int socket(int domain, int type, int protocol);
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
int somemopt (int req_type, char* mem, unsigned int memlen, int flags);
int socketlasterr(void);

View File

@ -133,7 +133,7 @@ typedef struct
#define OS_THREAD_TAG 0x74487244u
#pragma pack(push, 1)
typedef struct OSThread
typedef struct __attribute__ ((aligned (8))) OSThread
{
OSContext context;

View File

@ -32,6 +32,7 @@ IMPORT(OSIsThreadTerminated);
IMPORT(OSSetThreadPriority);
IMPORT(OSCreateThread);
IMPORT(OSSetThreadCleanupCallback);
IMPORT(OSSetThreadDeallocator);
IMPORT(OSResumeThread);
IMPORT(OSIsThreadSuspended);
IMPORT(OSSuspendThread);
@ -39,6 +40,7 @@ IMPORT(OSGetCurrentThread);
IMPORT(OSExitThread);
IMPORT(OSJoinThread);
IMPORT(OSYieldThread);
IMPORT(OSSetThreadName);
IMPORT(OSGetCoreId);
IMPORT(OSIsMainCore);
IMPORT(OSGetSystemTime);
@ -153,6 +155,12 @@ IMPORT(socketlasterr);
IMPORT_END();
IMPORT_BEGIN(nn_nets2);
IMPORT(somemopt);
IMPORT_END();
/* gx2 */
IMPORT_BEGIN(gx2);