Use O_NONBLOCK for platforms without support for FIONBIO

This commit is contained in:
Cameron Gutman 2021-07-01 22:15:26 -05:00
parent c00f4e15ae
commit 52250b4815
2 changed files with 5 additions and 1 deletions

View File

@ -32,6 +32,7 @@
#include <coreinit/thread.h>
#include <coreinit/fastmutex.h>
#include <coreinit/fastcondition.h>
#include <fcntl.h>
#else
#include <unistd.h>
#include <pthread.h>
@ -39,6 +40,7 @@
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <fcntl.h>
#endif
#ifdef _WIN32

View File

@ -299,11 +299,13 @@ int setSocketNonBlocking(SOCKET s, bool enabled) {
#if defined(__vita__)
int val = enabled ? 1 : 0;
return setsockopt(s, SOL_SOCKET, SO_NONBLOCK, (char*)&val, sizeof(val));
#elif defined(O_NONBLOCK)
return fcntl(s, F_SETFL, (enabled ? O_NONBLOCK : 0) | (fcntl(s, F_GETFL) & ~O_NONBLOCK));
#elif defined(FIONBIO)
int val = enabled ? 1 : 0;
return ioctlsocket(s, FIONBIO, &val);
#else
return SOCKET_ERROR;
#error Please define your platform's non-blocking sockets API!
#endif
}