miniupnpc: set timeout for select() in connecthostport()

This commit is contained in:
Thomas Bernard 2019-01-23 09:44:21 +01:00
parent 510a6e9630
commit 2656f41c7a
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C
2 changed files with 34 additions and 3 deletions

View File

@ -1,6 +1,9 @@
$Id: Changelog.txt,v 1.235 2018/05/07 11:05:16 nanard Exp $
miniUPnP client Changelog.
2019/01/23:
set timeout for select() in connecthostport()
VERSION 2.1 : released 2018/05/07
2018/05/07:

View File

@ -2,7 +2,7 @@
/* vim: tabstop=4 shiftwidth=4 noexpandtab
* Project : miniupnp
* Author : Thomas Bernard
* Copyright (c) 2010-2018 Thomas Bernard
* Copyright (c) 2010-2019 Thomas Bernard
* This software is subject to the conditions detailed in the
* LICENCE file provided in this distribution. */
@ -116,8 +116,22 @@ SOCKET connecthostport(const char * host, unsigned short port,
int err;
FD_ZERO(&wset);
FD_SET(s, &wset);
if((n = select(s + 1, NULL, &wset, NULL, NULL)) == -1 && errno == EINTR)
#ifdef MINIUPNPC_SET_SOCKET_TIMEOUT
timeout.tv_sec = 3;
timeout.tv_usec = 0;
n = select(s + 1, NULL, &wset, NULL, &timeout);
#else
n = select(s + 1, NULL, &wset, NULL, NULL);
#endif
if(n == -1 && errno == EINTR)
continue;
#ifdef MINIUPNPC_SET_SOCKET_TIMEOUT
if(n == 0) {
errno = ETIMEDOUT;
n = -1;
break;
}
#endif
/*len = 0;*/
/*n = getpeername(s, NULL, &len);*/
len = sizeof(err);
@ -213,8 +227,22 @@ SOCKET connecthostport(const char * host, unsigned short port,
int err;
FD_ZERO(&wset);
FD_SET(s, &wset);
if((n = select(s + 1, NULL, &wset, NULL, NULL)) == -1 && errno == EINTR)
#ifdef MINIUPNPC_SET_SOCKET_TIMEOUT
timeout.tv_sec = 3;
timeout.tv_usec = 0;
n = select(s + 1, NULL, &wset, NULL, &timeout);
#else
n = select(s + 1, NULL, &wset, NULL, NULL);
#endif
if(n == -1 && errno == EINTR)
continue;
#ifdef MINIUPNPC_SET_SOCKET_TIMEOUT
if(n == 0) {
errno = ETIMEDOUT;
n = -1;
break;
}
#endif
/*len = 0;*/
/*n = getpeername(s, NULL, &len);*/
len = sizeof(err);