mirror of
https://github.com/libretro/RetroArch
synced 2025-04-18 14:42:30 +00:00
Create socket_close in netplay_compat.c
This commit is contained in:
parent
57933ec70e
commit
cec500ece5
@ -153,7 +153,7 @@ void rarch_cmd_free(rarch_cmd_t *handle)
|
|||||||
{
|
{
|
||||||
#if defined(HAVE_NETWORK_CMD) && defined(HAVE_NETPLAY)
|
#if defined(HAVE_NETWORK_CMD) && defined(HAVE_NETPLAY)
|
||||||
if (handle && handle->net_fd >= 0)
|
if (handle && handle->net_fd >= 0)
|
||||||
close(handle->net_fd);
|
socket_close(handle->net_fd);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
free(handle);
|
free(handle);
|
||||||
@ -564,7 +564,7 @@ static bool send_udp_packet(const char *host,
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
socket_close(fd);
|
||||||
fd = -1;
|
fd = -1;
|
||||||
tmp = tmp->ai_next;
|
tmp = tmp->ai_next;
|
||||||
}
|
}
|
||||||
@ -572,7 +572,7 @@ static bool send_udp_packet(const char *host,
|
|||||||
end:
|
end:
|
||||||
freeaddrinfo_rarch(res);
|
freeaddrinfo_rarch(res);
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
close(fd);
|
socket_close(fd);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ static int net_http_new_socket(const char * domain, int port)
|
|||||||
if (connect(fd, addr->ai_addr, addr->ai_addrlen) != 0)
|
if (connect(fd, addr->ai_addr, addr->ai_addrlen) != 0)
|
||||||
{
|
{
|
||||||
freeaddrinfo_rarch(addr);
|
freeaddrinfo_rarch(addr);
|
||||||
close(fd);
|
socket_close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ static int net_http_new_socket(const char * domain, int port)
|
|||||||
|
|
||||||
if (!socket_nonblock(fd))
|
if (!socket_nonblock(fd))
|
||||||
{
|
{
|
||||||
close(fd);
|
socket_close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +243,7 @@ http_t *net_http_new(const char * url)
|
|||||||
|
|
||||||
fail:
|
fail:
|
||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
close(fd);
|
socket_close(fd);
|
||||||
free(urlcopy);
|
free(urlcopy);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -467,7 +467,7 @@ uint8_t* net_http_data(http_t *state, size_t* len, bool accept_error)
|
|||||||
void net_http_delete(http_t *state)
|
void net_http_delete(http_t *state)
|
||||||
{
|
{
|
||||||
if (state->fd != -1)
|
if (state->fd != -1)
|
||||||
close(state->fd);
|
socket_close(state->fd);
|
||||||
if (state->data)
|
if (state->data)
|
||||||
free(state->data);
|
free(state->data);
|
||||||
free(state);
|
free(state);
|
||||||
|
28
netplay.c
28
netplay.c
@ -686,7 +686,7 @@ static int init_tcp_connection(const struct addrinfo *res,
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
socket_close(fd);
|
||||||
fd = new_fd;
|
fd = new_fd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -694,7 +694,7 @@ static int init_tcp_connection(const struct addrinfo *res,
|
|||||||
end:
|
end:
|
||||||
if (!ret && fd >= 0)
|
if (!ret && fd >= 0)
|
||||||
{
|
{
|
||||||
close(fd);
|
socket_close(fd);
|
||||||
fd = -1;
|
fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -801,7 +801,7 @@ static bool init_udp_socket(netplay_t *netplay, const char *server,
|
|||||||
netplay->addr->ai_addrlen) < 0)
|
netplay->addr->ai_addrlen) < 0)
|
||||||
{
|
{
|
||||||
RARCH_ERR("Failed to bind socket.\n");
|
RARCH_ERR("Failed to bind socket.\n");
|
||||||
close(netplay->udp_fd);
|
socket_close(netplay->udp_fd);
|
||||||
netplay->udp_fd = -1;
|
netplay->udp_fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1286,9 +1286,9 @@ netplay_t *netplay_new(const char *server, uint16_t port,
|
|||||||
|
|
||||||
error:
|
error:
|
||||||
if (netplay->fd >= 0)
|
if (netplay->fd >= 0)
|
||||||
close(netplay->fd);
|
socket_close(netplay->fd);
|
||||||
if (netplay->udp_fd >= 0)
|
if (netplay->udp_fd >= 0)
|
||||||
close(netplay->udp_fd);
|
socket_close(netplay->udp_fd);
|
||||||
|
|
||||||
free(netplay);
|
free(netplay);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1374,19 +1374,19 @@ void netplay_free(netplay_t *netplay)
|
|||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
close(netplay->fd);
|
socket_close(netplay->fd);
|
||||||
|
|
||||||
if (netplay->spectate)
|
if (netplay->spectate)
|
||||||
{
|
{
|
||||||
for (i = 0; i < MAX_SPECTATORS; i++)
|
for (i = 0; i < MAX_SPECTATORS; i++)
|
||||||
if (netplay->spectate_fds[i] >= 0)
|
if (netplay->spectate_fds[i] >= 0)
|
||||||
close(netplay->spectate_fds[i]);
|
socket_close(netplay->spectate_fds[i]);
|
||||||
|
|
||||||
free(netplay->spectate_input);
|
free(netplay->spectate_input);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
close(netplay->udp_fd);
|
socket_close(netplay->udp_fd);
|
||||||
|
|
||||||
for (i = 0; i < netplay->buffer_size; i++)
|
for (i = 0; i < netplay->buffer_size; i++)
|
||||||
free(netplay->buffer[i].state);
|
free(netplay->buffer[i].state);
|
||||||
@ -1512,21 +1512,21 @@ static void netplay_pre_frame_spectate(netplay_t *netplay)
|
|||||||
/* No vacant client streams :( */
|
/* No vacant client streams :( */
|
||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
{
|
{
|
||||||
close(new_fd);
|
socket_close(new_fd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!get_nickname(netplay, new_fd))
|
if (!get_nickname(netplay, new_fd))
|
||||||
{
|
{
|
||||||
RARCH_ERR("Failed to get nickname from client.\n");
|
RARCH_ERR("Failed to get nickname from client.\n");
|
||||||
close(new_fd);
|
socket_close(new_fd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!send_nickname(netplay, new_fd))
|
if (!send_nickname(netplay, new_fd))
|
||||||
{
|
{
|
||||||
RARCH_ERR("Failed to send nickname to client.\n");
|
RARCH_ERR("Failed to send nickname to client.\n");
|
||||||
close(new_fd);
|
socket_close(new_fd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1536,7 +1536,7 @@ static void netplay_pre_frame_spectate(netplay_t *netplay)
|
|||||||
if (!header)
|
if (!header)
|
||||||
{
|
{
|
||||||
RARCH_ERR("Failed to generate BSV header.\n");
|
RARCH_ERR("Failed to generate BSV header.\n");
|
||||||
close(new_fd);
|
socket_close(new_fd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1547,7 +1547,7 @@ static void netplay_pre_frame_spectate(netplay_t *netplay)
|
|||||||
if (!send_all(new_fd, header, header_size))
|
if (!send_all(new_fd, header, header_size))
|
||||||
{
|
{
|
||||||
RARCH_ERR("Failed to send header to client.\n");
|
RARCH_ERR("Failed to send header to client.\n");
|
||||||
close(new_fd);
|
socket_close(new_fd);
|
||||||
free(header);
|
free(header);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1668,7 +1668,7 @@ static void netplay_post_frame_spectate(netplay_t *netplay)
|
|||||||
snprintf(msg, sizeof(msg), "Client (#%u) disconnected.", i);
|
snprintf(msg, sizeof(msg), "Client (#%u) disconnected.", i);
|
||||||
msg_queue_push(g_extern.msg_queue, msg, 1, 180);
|
msg_queue_push(g_extern.msg_queue, msg, 1, 180);
|
||||||
|
|
||||||
close(netplay->spectate_fds[i]);
|
socket_close(netplay->spectate_fds[i]);
|
||||||
netplay->spectate_fds[i] = -1;
|
netplay->spectate_fds[i] = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -98,3 +98,15 @@ bool socket_nonblock(int fd)
|
|||||||
return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK) == 0;
|
return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK) == 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int socket_close(int fd)
|
||||||
|
{
|
||||||
|
#if defined(_WIN32) && !defined(_XBOX360)
|
||||||
|
/* WinSock has headers from the stone age. */
|
||||||
|
return closesocket(fd);
|
||||||
|
#elif defined(__CELLOS_LV2__)
|
||||||
|
return socketclose(fd);
|
||||||
|
#else
|
||||||
|
return close(fd);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
@ -77,18 +77,11 @@
|
|||||||
#define MSG_NOSIGNAL 0
|
#define MSG_NOSIGNAL 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#ifndef _WIN32
|
||||||
/* Woohoo, Winsock has headers
|
|
||||||
* from the STONE AGE. :D */
|
|
||||||
#ifndef _XBOX360
|
|
||||||
#define close(x) closesocket(x)
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#if defined(__CELLOS_LV2__)
|
#if defined(__CELLOS_LV2__)
|
||||||
#define close(x) socketclose(x)
|
|
||||||
#define select(nfds, readfds, writefds, errorfds, timeout) socketselect(nfds, readfds, writefds, errorfds, timeout)
|
#define select(nfds, readfds, writefds, errorfds, timeout) socketselect(nfds, readfds, writefds, errorfds, timeout)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@ -130,5 +123,7 @@ void freeaddrinfo_rarch(struct addrinfo *res);
|
|||||||
|
|
||||||
bool socket_nonblock(int fd);
|
bool socket_nonblock(int fd);
|
||||||
|
|
||||||
|
int socket_close(int fd);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user