miniupnpc/miniupnpc.c: don't wait several times for the timeout in upnpDiscoverDevices()

This commit is contained in:
Thomas Bernard 2015-05-22 12:44:38 +02:00
parent 0bf168d306
commit a2adfcd05d

View File

@ -1,4 +1,4 @@
/* $Id: miniupnpc.c,v 1.126 2015/05/22 10:12:58 nanard Exp $ */ /* $Id: miniupnpc.c,v 1.127 2015/05/22 10:42:46 nanard Exp $ */
/* Project : miniupnp /* Project : miniupnp
* Web : http://miniupnp.free.fr/ * Web : http://miniupnp.free.fr/
* Author : Thomas BERNARD * Author : Thomas BERNARD
@ -653,8 +653,10 @@ upnpDiscoverDevices(const char * const deviceTypes[],
break; break;
} }
#endif /* #ifdef NO_GETADDRINFO */ #endif /* #ifdef NO_GETADDRINFO */
/* Waiting for SSDP REPLY packet to M-SEARCH */ /* Waiting for SSDP REPLY packet to M-SEARCH
do { * if searchalltypes is set, enter the loop only
* when the last deviceType is reached */
if(!searchalltypes || !deviceTypes[deviceIndex + 1]) do {
n = receivedata(sudp, bufr, sizeof(bufr), delay, &scope_id); n = receivedata(sudp, bufr, sizeof(bufr), delay, &scope_id);
if (n < 0) { if (n < 0) {
/* error */ /* error */
@ -663,21 +665,15 @@ upnpDiscoverDevices(const char * const deviceTypes[],
goto error; goto error;
} else if (n == 0) { } else if (n == 0) {
/* no data or Time Out */ /* no data or Time Out */
#ifdef DEBUG
printf("NODATA or TIMEOUT\n");
#endif /* DEBUG */
if (devlist && !searchalltypes) { if (devlist && !searchalltypes) {
/* found some devices, stop now*/ /* found some devices, stop now*/
if(error) if(error)
*error = UPNPDISCOVER_SUCCESS; *error = UPNPDISCOVER_SUCCESS;
goto error; goto error;
} }
if(ipv6) {
/* switch linklocal flag */
if(linklocal) {
linklocal = 0;
--deviceIndex;
} else {
linklocal = 1;
}
}
} else { } else {
const char * descURL=NULL; const char * descURL=NULL;
int urlsize=0; int urlsize=0;
@ -688,7 +684,7 @@ upnpDiscoverDevices(const char * const deviceTypes[],
#ifdef DEBUG #ifdef DEBUG
printf("M-SEARCH Reply:\n ST: %.*s\n Location: %.*s\n", printf("M-SEARCH Reply:\n ST: %.*s\n Location: %.*s\n",
stsize, st, urlsize, descURL); stsize, st, urlsize, descURL);
#endif #endif /* DEBUG */
for(tmp=devlist; tmp; tmp = tmp->pNext) { for(tmp=devlist; tmp; tmp = tmp->pNext) {
if(memcmp(tmp->descURL, descURL, urlsize) == 0 && if(memcmp(tmp->descURL, descURL, urlsize) == 0 &&
tmp->descURL[urlsize] == '\0' && tmp->descURL[urlsize] == '\0' &&
@ -719,6 +715,15 @@ upnpDiscoverDevices(const char * const deviceTypes[],
} }
} }
} while(n > 0); } while(n > 0);
if(ipv6) {
/* switch linklocal flag */
if(linklocal) {
linklocal = 0;
--deviceIndex;
} else {
linklocal = 1;
}
}
} }
error: error:
closesocket(sudp); closesocket(sudp);