mirror of
https://github.com/libretro/RetroArch
synced 2025-02-21 18:40:09 +00:00
Fix crash in Windows when UDP CMD was disabled.
This commit is contained in:
parent
066e13f647
commit
f8a57ef690
62
command.c
62
command.c
@ -60,20 +60,14 @@ static bool socket_nonblock(int fd)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
rarch_cmd_t *rarch_cmd_new(bool stdin_enable, bool network_enable, uint16_t port)
|
|
||||||
{
|
|
||||||
rarch_cmd_t *handle = (rarch_cmd_t*)calloc(1, sizeof(*handle));
|
|
||||||
if (!handle)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
#ifdef HAVE_NETWORK_CMD
|
#ifdef HAVE_NETWORK_CMD
|
||||||
if (network_enable && !netplay_init_network())
|
static bool cmd_init_network(rarch_cmd_t *handle, uint16_t port)
|
||||||
return NULL;
|
{
|
||||||
|
if (!netplay_init_network())
|
||||||
|
return false;
|
||||||
|
|
||||||
RARCH_LOG("Bringing up command interface on port %hu.\n", (unsigned short)port);
|
RARCH_LOG("Bringing up command interface on port %hu.\n", (unsigned short)port);
|
||||||
|
|
||||||
handle->net_fd = -1;
|
|
||||||
|
|
||||||
struct addrinfo hints, *res = NULL;
|
struct addrinfo hints, *res = NULL;
|
||||||
memset(&hints, 0, sizeof(hints));
|
memset(&hints, 0, sizeof(hints));
|
||||||
#if defined(_WIN32) || defined(HAVE_SOCKET_LEGACY)
|
#if defined(_WIN32) || defined(HAVE_SOCKET_LEGACY)
|
||||||
@ -104,31 +98,57 @@ rarch_cmd_t *rarch_cmd_new(bool stdin_enable, bool network_enable, uint16_t port
|
|||||||
RARCH_ERR("Failed to bind socket.\n");
|
RARCH_ERR("Failed to bind socket.\n");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
freeaddrinfo(res);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
error:
|
||||||
|
if (res)
|
||||||
|
freeaddrinfo(res);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_STDIN_CMD
|
||||||
|
static bool cmd_init_stdin(rarch_cmd_t *handle)
|
||||||
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
|
if (stdin_enable && !socket_nonblock(STDIN_FILENO))
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
handle->stdin_enable = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
rarch_cmd_t *rarch_cmd_new(bool stdin_enable, bool network_enable, uint16_t port)
|
||||||
|
{
|
||||||
|
rarch_cmd_t *handle = (rarch_cmd_t*)calloc(1, sizeof(*handle));
|
||||||
|
if (!handle)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
handle->net_fd = -1;
|
||||||
|
handle->stdin_enable = stdin_enable;
|
||||||
|
|
||||||
|
#ifdef HAVE_NETWORK_CMD
|
||||||
|
if (network_enable && !cmd_init_network(handle, port))
|
||||||
|
goto error;
|
||||||
#else
|
#else
|
||||||
(void)network_enable;
|
(void)network_enable;
|
||||||
(void)port;
|
(void)port;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_STDIN_CMD
|
#ifdef HAVE_STDIN_CMD
|
||||||
#ifndef _WIN32
|
if (stdin_enable && !cmd_init_stdin(handle))
|
||||||
if (stdin_enable && !socket_nonblock(STDIN_FILENO))
|
|
||||||
goto error;
|
goto error;
|
||||||
#endif
|
|
||||||
handle->stdin_enable = stdin_enable;
|
|
||||||
#else
|
#else
|
||||||
(void)stdin_enable;
|
(void)stdin_enable;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_NETWORK_CMD
|
|
||||||
freeaddrinfo(res);
|
|
||||||
#endif
|
|
||||||
return handle;
|
return handle;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
#ifdef HAVE_NETWORK_CMD
|
|
||||||
if (res)
|
|
||||||
freeaddrinfo(res);
|
|
||||||
#endif
|
|
||||||
rarch_cmd_free(handle);
|
rarch_cmd_free(handle);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user