mirror of
https://github.com/libretro/RetroArch
synced 2025-04-02 07:20:34 +00:00
(Network) Get rid of the timeout_enable parameter for socket_connect (#14351)
This commit is contained in:
parent
23f649b050
commit
e45958b25a
@ -119,20 +119,16 @@ static void *network_gfx_init(const video_info_t *video,
|
|||||||
try_connect:
|
try_connect:
|
||||||
fd = socket_init((void**)&addr, network->port, network->address, SOCKET_TYPE_STREAM, 0);
|
fd = socket_init((void**)&addr, network->port, network->address, SOCKET_TYPE_STREAM, 0);
|
||||||
|
|
||||||
next_addr = addr;
|
for (next_addr = addr; fd >= 0; fd = socket_next((void**)&next_addr))
|
||||||
|
|
||||||
while (fd >= 0)
|
|
||||||
{
|
{
|
||||||
|
if (socket_connect_with_timeout(fd, next_addr, 5000))
|
||||||
{
|
{
|
||||||
int ret = socket_connect(fd, (void*)next_addr, true);
|
/* socket_connect_with_timeout makes the socket non-blocking. */
|
||||||
|
if (socket_set_block(fd, true))
|
||||||
if (ret >= 0) /* && socket_nonblock(fd)) */
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
socket_close(fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = socket_next((void**)&next_addr);
|
socket_close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addr)
|
if (addr)
|
||||||
@ -140,11 +136,7 @@ try_connect:
|
|||||||
|
|
||||||
network->fd = fd;
|
network->fd = fd;
|
||||||
|
|
||||||
#if 0
|
if (network->fd >= 0)
|
||||||
socket_nonblock(network->fd);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (network->fd > 0)
|
|
||||||
RARCH_LOG("[Network]: Connected to host.\n");
|
RARCH_LOG("[Network]: Connected to host.\n");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -156,11 +148,6 @@ try_connect:
|
|||||||
RARCH_LOG("[Network]: Init complete.\n");
|
RARCH_LOG("[Network]: Init complete.\n");
|
||||||
|
|
||||||
return network;
|
return network;
|
||||||
|
|
||||||
error:
|
|
||||||
if (network)
|
|
||||||
free(network);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool network_gfx_frame(void *data, const void *frame,
|
static bool network_gfx_frame(void *data, const void *frame,
|
||||||
|
@ -101,7 +101,7 @@ ssize_t socket_receive_all_nonblocking(int fd, bool *error,
|
|||||||
|
|
||||||
bool socket_bind(int fd, void *data);
|
bool socket_bind(int fd, void *data);
|
||||||
|
|
||||||
int socket_connect(int fd, void *data, bool timeout_enable);
|
int socket_connect(int fd, void *data);
|
||||||
|
|
||||||
bool socket_connect_with_timeout(int fd, void *data, int timeout);
|
bool socket_connect_with_timeout(int fd, void *data, int timeout);
|
||||||
|
|
||||||
|
@ -431,37 +431,35 @@ static int net_http_new_socket(struct http_connection_t *conn)
|
|||||||
#ifdef HAVE_SSL
|
#ifdef HAVE_SSL
|
||||||
if (conn->sock_state.ssl)
|
if (conn->sock_state.ssl)
|
||||||
{
|
{
|
||||||
|
if (fd < 0)
|
||||||
|
goto done;
|
||||||
|
|
||||||
if (!(conn->sock_state.ssl_ctx = ssl_socket_init(fd, conn->domain)))
|
if (!(conn->sock_state.ssl_ctx = ssl_socket_init(fd, conn->domain)))
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
next_addr = addr;
|
|
||||||
|
|
||||||
while (fd >= 0)
|
|
||||||
{
|
|
||||||
#ifdef HAVE_SSL
|
|
||||||
if (conn->sock_state.ssl)
|
|
||||||
{
|
{
|
||||||
if (ssl_socket_connect(conn->sock_state.ssl_ctx,
|
|
||||||
(void*)next_addr, true, true) >= 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
ssl_socket_close(conn->sock_state.ssl_ctx);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
if ( socket_connect(fd, (void*)next_addr, true) >= 0
|
|
||||||
&& socket_nonblock(fd))
|
|
||||||
break;
|
|
||||||
|
|
||||||
socket_close(fd);
|
socket_close(fd);
|
||||||
|
fd = -1;
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
|
if (ssl_socket_connect(conn->sock_state.ssl_ctx, addr, true, true)
|
||||||
|
< 0)
|
||||||
|
{
|
||||||
|
fd = -1;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
for (next_addr = addr; fd >= 0; fd = socket_next((void**)&next_addr))
|
||||||
|
{
|
||||||
|
if (socket_connect_with_timeout(fd, next_addr, 5000))
|
||||||
|
break;
|
||||||
|
|
||||||
fd = socket_next((void**)&next_addr);
|
socket_close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_SSL
|
||||||
|
done:
|
||||||
|
#endif
|
||||||
if (addr)
|
if (addr)
|
||||||
freeaddrinfo_retro(addr);
|
freeaddrinfo_retro(addr);
|
||||||
|
|
||||||
@ -864,7 +862,7 @@ error:
|
|||||||
conn->postdatacopy = NULL;
|
conn->postdatacopy = NULL;
|
||||||
}
|
}
|
||||||
#ifdef HAVE_SSL
|
#ifdef HAVE_SSL
|
||||||
if (conn && conn->sock_state.ssl && conn->sock_state.ssl_ctx && fd >= 0)
|
if (conn && conn->sock_state.ssl_ctx)
|
||||||
{
|
{
|
||||||
ssl_socket_close(conn->sock_state.ssl_ctx);
|
ssl_socket_close(conn->sock_state.ssl_ctx);
|
||||||
ssl_socket_free(conn->sock_state.ssl_ctx);
|
ssl_socket_free(conn->sock_state.ssl_ctx);
|
||||||
|
@ -660,21 +660,10 @@ bool socket_bind(int fd, void *data)
|
|||||||
return !bind(fd, addr->ai_addr, addr->ai_addrlen);
|
return !bind(fd, addr->ai_addr, addr->ai_addrlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
int socket_connect(int fd, void *data, bool timeout_enable)
|
int socket_connect(int fd, void *data)
|
||||||
{
|
{
|
||||||
struct addrinfo *addr = (struct addrinfo*)data;
|
struct addrinfo *addr = (struct addrinfo*)data;
|
||||||
|
|
||||||
#if !defined(_WIN32) && !defined(VITA) && !defined(WIIU) && !defined(_3DS)
|
|
||||||
if (timeout_enable)
|
|
||||||
{
|
|
||||||
struct timeval timeout;
|
|
||||||
timeout.tv_sec = 4;
|
|
||||||
timeout.tv_usec = 0;
|
|
||||||
|
|
||||||
setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (char*)&timeout, sizeof(timeout));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef WIIU
|
#ifdef WIIU
|
||||||
{
|
{
|
||||||
int op = 1;
|
int op = 1;
|
||||||
|
@ -222,8 +222,19 @@ int ssl_socket_connect(void *state_data,
|
|||||||
struct ssl_state *state = (struct ssl_state*)state_data;
|
struct ssl_state *state = (struct ssl_state*)state_data;
|
||||||
unsigned bearstate;
|
unsigned bearstate;
|
||||||
|
|
||||||
if (socket_connect(state->fd, data, timeout_enable))
|
if (timeout_enable)
|
||||||
return -1;
|
{
|
||||||
|
if (!socket_connect_with_timeout(state->fd, data, 5000))
|
||||||
|
return -1;
|
||||||
|
/* socket_connect_with_timeout makes the socket non-blocking. */
|
||||||
|
if (!socket_set_block(state->fd, true))
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (socket_connect(state->fd, data))
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
@ -115,8 +115,19 @@ int ssl_socket_connect(void *state_data,
|
|||||||
int ret, flags;
|
int ret, flags;
|
||||||
struct ssl_state *state = (struct ssl_state*)state_data;
|
struct ssl_state *state = (struct ssl_state*)state_data;
|
||||||
|
|
||||||
if (socket_connect(state->net_ctx.fd, data, timeout_enable))
|
if (timeout_enable)
|
||||||
return -1;
|
{
|
||||||
|
if (!socket_connect_with_timeout(state->net_ctx.fd, data, 5000))
|
||||||
|
return -1;
|
||||||
|
/* socket_connect_with_timeout makes the socket non-blocking. */
|
||||||
|
if (!socket_set_block(state->net_ctx.fd, true))
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (socket_connect(state->net_ctx.fd, data))
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (mbedtls_ssl_config_defaults(&state->conf,
|
if (mbedtls_ssl_config_defaults(&state->conf,
|
||||||
MBEDTLS_SSL_IS_CLIENT,
|
MBEDTLS_SSL_IS_CLIENT,
|
||||||
|
@ -3207,7 +3207,7 @@ static bool netplay_tunnel_connect(int fd, const struct addrinfo *addr)
|
|||||||
SET_TCP_NODELAY(fd)
|
SET_TCP_NODELAY(fd)
|
||||||
SET_FD_CLOEXEC(fd)
|
SET_FD_CLOEXEC(fd)
|
||||||
|
|
||||||
result = socket_connect(fd, (void*)addr, false);
|
result = socket_connect(fd, (void*)addr);
|
||||||
if (result && !isinprogress(result) && !isagain(result))
|
if (result && !isinprogress(result) && !isagain(result))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ int main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (socket_connect(sock, addr, false) < 0)
|
if (socket_connect(sock, addr) < 0)
|
||||||
{
|
{
|
||||||
perror("connect");
|
perror("connect");
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user