SOCK_NONBLOCK doesn't exist on Win32.

This commit is contained in:
Themaister 2012-05-27 14:16:24 +02:00
parent 0375de48a2
commit 0b729e1707

View File

@ -19,6 +19,7 @@
#include "general.h"
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
struct network_cmd
{
@ -26,6 +27,16 @@ struct network_cmd
bool state[RARCH_BIND_LIST_END];
};
static bool socket_nonblock(int fd)
{
#ifdef _WIN32
u_long mode = 1;
ioctlsocket(fd, FIONBIO, &mode);
#else
return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK) == 0;
#endif
}
network_cmd_t *network_cmd_new(uint16_t port)
{
network_cmd_t *handle = (network_cmd_t*)calloc(1, sizeof(*handle));
@ -51,10 +62,13 @@ network_cmd_t *network_cmd_new(uint16_t port)
if (getaddrinfo(NULL, port_buf, &hints, &res) < 0)
goto error;
handle->fd = socket(res->ai_family, res->ai_socktype | SOCK_NONBLOCK, res->ai_protocol);
handle->fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (handle->fd < 0)
goto error;
if (!socket_nonblock(handle->fd))
goto error;
setsockopt(handle->fd, SOL_SOCKET, SO_REUSEADDR, CONST_CAST &yes, sizeof(int));
if (bind(handle->fd, res->ai_addr, res->ai_addrlen) < 0)
{