diff --git a/command.c b/command.c index b5bc202332..1a09e88085 100644 --- a/command.c +++ b/command.c @@ -52,16 +52,6 @@ struct rarch_cmd bool state[RARCH_BIND_LIST_END]; }; -static bool socket_nonblock(int fd) -{ -#ifdef _WIN32 - u_long mode = 1; - return ioctlsocket(fd, FIONBIO, &mode) == 0; -#else - return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK) == 0; -#endif -} - #if defined(HAVE_NETWORK_CMD) && defined(HAVE_NETPLAY) static bool cmd_init_network(rarch_cmd_t *handle, uint16_t port) { diff --git a/net_http.c b/net_http.c index 3ee3280c77..554d5a0810 100644 --- a/net_http.c +++ b/net_http.c @@ -18,7 +18,6 @@ #include #include #include -#include #include "netplay_compat.h" enum @@ -117,16 +116,11 @@ static int net_http_new_socket(const char * domain, int port) freeaddrinfo_rarch(addr); -#if defined(__CELLOS_LV2__) - setsockopt(fd, SOL_SOCKET, SO_NBIO, &i, sizeof(int)); - setsockopt(fd, SOL_SOCKET, SO_NBIO, &i, sizeof(int)); -#elif defined(_WIN32) - ioctlsocket(fd, FIONBIO, &mode); -#else - fcntl(fd, F_SETFL, O_NONBLOCK); - fcntl(fd, F_SETFL, O_NONBLOCK); -#endif - + if (!socket_nonblock(fd)) + { + close(fd); + return -1; + } return fd; } diff --git a/netplay_compat.c b/netplay_compat.c index f47bd50e84..19f6e5867b 100644 --- a/netplay_compat.c +++ b/netplay_compat.c @@ -83,3 +83,18 @@ void freeaddrinfo_rarch(struct addrinfo *res) freeaddrinfo(res); #endif } + +bool socket_nonblock(int fd) +{ +#if defined(__CELLOS_LV2__) + int i = 1; + setsockopt(fd, SOL_SOCKET, SO_NBIO, &i, sizeof(int)); + setsockopt(fd, SOL_SOCKET, SO_NBIO, &i, sizeof(int)); + return true; +#elif defined(_WIN32) + u_long mode = 1; + return ioctlsocket(fd, FIONBIO, &mode) == 0; +#else + return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK) == 0; +#endif +} diff --git a/netplay_compat.h b/netplay_compat.h index 31208103f8..ea4ef1297e 100644 --- a/netplay_compat.h +++ b/netplay_compat.h @@ -21,6 +21,8 @@ #include "config.h" #endif +#include + #if defined(_WIN32) && !defined(_XBOX) #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0501 @@ -129,5 +131,8 @@ int getaddrinfo_rarch(const char *node, const char *service, struct addrinfo **res); void freeaddrinfo_rarch(struct addrinfo *res); + +bool socket_nonblock(int fd); + #endif