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