* Take notifications back out of their own thread, and rely on select timeouts.
* Increment SystemUpdateID as necessary just before processing new HTTP requests.
This commit is contained in:
88
minissdp.c
88
minissdp.c
@ -12,7 +12,6 @@
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/time.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "config.h"
|
||||
@ -20,8 +19,6 @@
|
||||
#include "minidlnapath.h"
|
||||
#include "upnphttp.h"
|
||||
#include "upnpglobalvars.h"
|
||||
#include "upnpevents.h"
|
||||
#include "tivo_beacon.h"
|
||||
#include "minissdp.h"
|
||||
#include "log.h"
|
||||
|
||||
@ -306,6 +303,7 @@ SendSSDPNotifies2(int * sockets,
|
||||
unsigned int lifetime)*/
|
||||
{
|
||||
int i;
|
||||
DPRINTF(E_DEBUG, L_SSDP, "Sending SSDP notifies\n");
|
||||
for(i=0; i<n_lan_addr; i++)
|
||||
{
|
||||
SendSSDPNotifies(sockets[i], lan_addr[i].str, port, lifetime);
|
||||
@ -498,87 +496,3 @@ SendSSDPGoodbye(int * sockets, int n_sockets)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
start_notify(void * arg)
|
||||
{
|
||||
struct sockets *s = (struct sockets *)arg;
|
||||
struct timeval timeofday, lasttimeofday = {0, 0}, lastupdatetime = {0, 0};
|
||||
int last_changecnt = 0;
|
||||
#ifdef TIVO_SUPPORT
|
||||
short int loop_cnt = 0;
|
||||
#endif
|
||||
|
||||
while(1)
|
||||
{
|
||||
/* Check if we need to send SSDP NOTIFY messages and do it if needed */
|
||||
/* Also check if we need to increment our SystemUpdateID
|
||||
* at most once every 2 seconds */
|
||||
if(gettimeofday(&timeofday, 0) < 0)
|
||||
{
|
||||
DPRINTF(E_ERROR, L_GENERAL, "gettimeofday(): %s\n", strerror(errno));
|
||||
s->timeout->tv_sec = runtime_vars.notify_interval;
|
||||
s->timeout->tv_usec = 0;
|
||||
sleep(2);
|
||||
continue;
|
||||
}
|
||||
/* the comparaison is not very precise but who cares ? */
|
||||
if(timeofday.tv_sec >= (lasttimeofday.tv_sec + runtime_vars.notify_interval))
|
||||
{
|
||||
SendSSDPNotifies2(s->snotify,
|
||||
runtime_vars.port,
|
||||
(runtime_vars.notify_interval << 1)+10);
|
||||
memcpy(&lasttimeofday, &timeofday, sizeof(struct timeval));
|
||||
s->timeout->tv_sec = runtime_vars.notify_interval;
|
||||
s->timeout->tv_usec = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
s->timeout->tv_sec = lasttimeofday.tv_sec + runtime_vars.notify_interval
|
||||
- timeofday.tv_sec;
|
||||
if(timeofday.tv_usec > lasttimeofday.tv_usec)
|
||||
{
|
||||
s->timeout->tv_usec = 1000000 + lasttimeofday.tv_usec
|
||||
- timeofday.tv_usec;
|
||||
s->timeout->tv_sec--;
|
||||
}
|
||||
else
|
||||
{
|
||||
s->timeout->tv_usec = lasttimeofday.tv_usec - timeofday.tv_usec;
|
||||
}
|
||||
}
|
||||
if(timeofday.tv_sec >= (lastupdatetime.tv_sec + 2))
|
||||
{
|
||||
if( sqlite3_total_changes(db) != last_changecnt )
|
||||
{
|
||||
updateID++;
|
||||
last_changecnt = sqlite3_total_changes(db);
|
||||
upnp_event_var_change_notify(EContentDirectory);
|
||||
}
|
||||
#ifdef TIVO_SUPPORT
|
||||
if( GETFLAG(TIVOMASK) )
|
||||
{
|
||||
if( loop_cnt < 20 )
|
||||
{
|
||||
if(loop_cnt % 3 == 0)
|
||||
sendBeaconMessage(s->sbeacon, &(s->tivo_bcast), sizeof(struct sockaddr_in), 1);
|
||||
loop_cnt++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( loop_cnt == 50 )
|
||||
{
|
||||
sendBeaconMessage(s->sbeacon, &(s->tivo_bcast), sizeof(struct sockaddr_in), 1);
|
||||
loop_cnt = 20;
|
||||
}
|
||||
loop_cnt++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
memcpy(&lastupdatetime, &timeofday, sizeof(struct timeval));
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
Reference in New Issue
Block a user