diff --git a/libretro-common/include/net/net_socket.h b/libretro-common/include/net/net_socket.h index 15b0785a14..31960cd96e 100644 --- a/libretro-common/include/net/net_socket.h +++ b/libretro-common/include/net/net_socket.h @@ -52,6 +52,8 @@ int socket_receive_all_blocking(int fd, void *data_, size_t size); bool socket_bind(int fd, void *data); +int socket_connect(int fd, void *data, bool timeout_enable); + RETRO_END_DECLS #endif diff --git a/libretro-common/net/net_http.c b/libretro-common/net/net_http.c index df0eb39d26..46d2a462b2 100644 --- a/libretro-common/net/net_http.c +++ b/libretro-common/net/net_http.c @@ -74,25 +74,12 @@ struct http_connection_t static int net_http_new_socket(const char *domain, int port) { int ret; -#ifndef _WIN32 -#ifndef VITA - struct timeval timeout; -#endif -#endif struct addrinfo *addr = NULL; int fd = socket_init((void**)&addr, port, domain, SOCKET_TYPE_STREAM); if (fd == -1) return -1; -#ifndef _WIN32 -#ifndef VITA - timeout.tv_sec=4; - timeout.tv_usec=0; - setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (char*)&timeout, sizeof timeout); -#endif -#endif - - ret = connect(fd, addr->ai_addr, addr->ai_addrlen); + ret = socket_connect(fd, (void*)addr, true); freeaddrinfo_retro(addr); diff --git a/libretro-common/net/net_socket.c b/libretro-common/net/net_socket.c index 45f7724276..b1e827775d 100644 --- a/libretro-common/net/net_socket.c +++ b/libretro-common/net/net_socket.c @@ -172,3 +172,23 @@ bool socket_bind(int fd, void *data) return false; return true; } + +int socket_connect(int fd, void *data, bool timeout_enable) +{ + struct addrinfo *addr = (struct addrinfo*)data; + +#ifndef _WIN32 +#ifndef VITA + 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 +#endif + + return connect(fd, addr->ai_addr, addr->ai_addrlen); +} diff --git a/netplay/netplay.c b/netplay/netplay.c index b6fc9feb96..e12f95bce7 100644 --- a/netplay/netplay.c +++ b/netplay/netplay.c @@ -659,7 +659,7 @@ static int init_tcp_connection(const struct addrinfo *res, if (server) { - if (connect(fd, res->ai_addr, res->ai_addrlen) < 0) + if (socket_connect(fd, (void*)res, false) < 0) { ret = false; goto end;