minissdp: Delay before answering ssdp:all requests

With some device combinations, our responses may be lost if we don't
delay for some time.
This commit is contained in:
Justin Maggard 2018-01-08 18:04:57 -08:00
parent 0d224a4607
commit 33fd018828

View File

@ -204,9 +204,10 @@ static const char * const known_service_types[] =
}; };
static void static void
_usleep(long usecs) _usleep(long min, long max)
{ {
struct timespec sleep_time; struct timespec sleep_time;
long usecs = min + rand() / (RAND_MAX / (max - min + 1) + 1);
sleep_time.tv_sec = 0; sleep_time.tv_sec = 0;
sleep_time.tv_nsec = usecs * 1000; sleep_time.tv_nsec = usecs * 1000;
@ -278,7 +279,7 @@ SendSSDPNotifies(int s, const char *host, unsigned short port,
for (dup = 0; dup < 2; dup++) for (dup = 0; dup < 2; dup++)
{ {
if (dup) if (dup)
_usleep(200000); _usleep(150000, 250000);
i = 0; i = 0;
while (known_service_types[i]) while (known_service_types[i])
{ {
@ -722,7 +723,7 @@ ProcessSSDPRequest(int s, unsigned short port)
if (l != st_len) if (l != st_len)
break; break;
} }
_usleep(random()>>20); _usleep(13000, 20000);
SendSSDPResponse(s, sendername, i, SendSSDPResponse(s, sendername, i,
host, port, len_r); host, port, len_r);
return; return;
@ -731,6 +732,7 @@ ProcessSSDPRequest(int s, unsigned short port)
/* strlen("ssdp:all") == 8 */ /* strlen("ssdp:all") == 8 */
if ((st_len == 8) && (memcmp(st, "ssdp:all", 8) == 0)) if ((st_len == 8) && (memcmp(st, "ssdp:all", 8) == 0))
{ {
_usleep(13000, 30000);
for (i=0; known_service_types[i]; i++) for (i=0; known_service_types[i]; i++)
{ {
l = strlen(known_service_types[i]); l = strlen(known_service_types[i]);