Create socket_connect

This commit is contained in:
twinaphex 2016-05-01 23:45:59 +02:00
parent 2b3eeef2fa
commit 2e1fa648b8
4 changed files with 24 additions and 15 deletions

View File

@ -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

View File

@ -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);

View File

@ -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);
}

View File

@ -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;