Lines 1109-1115
main(int argc, char **argv)
Link Here
|
1109 |
struct upnphttp * next; |
1109 |
struct upnphttp * next; |
1110 |
struct timeval tv, timeofday, lastnotifytime = {0, 0}; |
1110 |
struct timeval tv, timeofday, lastnotifytime = {0, 0}; |
1111 |
time_t lastupdatetime = 0, lastdbtime = 0; |
1111 |
time_t lastupdatetime = 0, lastdbtime = 0; |
1112 |
u_long timeout; /* in milliseconds */ |
|
|
1113 |
int last_changecnt = 0; |
1112 |
int last_changecnt = 0; |
1114 |
pid_t scanner_pid = 0; |
1113 |
pid_t scanner_pid = 0; |
1115 |
struct event ssdpev, httpev, monev; |
1114 |
struct event ssdpev, httpev, monev; |
Lines 1181-1186
main(int argc, char **argv)
Link Here
|
1181 |
httpev = (struct event ){ .fd = shttpl, .rdwr = EVENT_READ, .process = ProcessListen }; |
1180 |
httpev = (struct event ){ .fd = shttpl, .rdwr = EVENT_READ, .process = ProcessListen }; |
1182 |
event_module.add(&httpev); |
1181 |
event_module.add(&httpev); |
1183 |
|
1182 |
|
|
|
1183 |
if (gettimeofday(&timeofday, 0) < 0) |
1184 |
DPRINTF(E_FATAL, L_GENERAL, "gettimeofday(): %s\n", strerror(errno)); |
1185 |
|
1184 |
#ifdef TIVO_SUPPORT |
1186 |
#ifdef TIVO_SUPPORT |
1185 |
if (GETFLAG(TIVO_MASK)) |
1187 |
if (GETFLAG(TIVO_MASK)) |
1186 |
{ |
1188 |
{ |
Lines 1205-1222
main(int argc, char **argv)
Link Here
|
1205 |
tivo_bcast.sin_family = AF_INET; |
1207 |
tivo_bcast.sin_family = AF_INET; |
1206 |
tivo_bcast.sin_addr.s_addr = htonl(getBcastAddress()); |
1208 |
tivo_bcast.sin_addr.s_addr = htonl(getBcastAddress()); |
1207 |
tivo_bcast.sin_port = htons(2190); |
1209 |
tivo_bcast.sin_port = htons(2190); |
|
|
1210 |
lastbeacontime = timeofday; |
1208 |
} |
1211 |
} |
1209 |
} |
1212 |
} |
1210 |
#endif |
1213 |
#endif |
1211 |
|
1214 |
|
1212 |
reload_ifaces(0); |
1215 |
reload_ifaces(0); /* sends SSDP notifies */ |
1213 |
lastnotifytime.tv_sec = time(NULL) + runtime_vars.notify_interval; |
1216 |
lastnotifytime = timeofday; |
1214 |
|
1217 |
|
1215 |
/* main loop */ |
1218 |
/* main loop */ |
1216 |
while (!quitting) |
1219 |
while (!quitting) |
1217 |
{ |
1220 |
{ |
1218 |
if (gettimeofday(&timeofday, 0) < 0) |
|
|
1219 |
DPRINTF(E_FATAL, L_GENERAL, "gettimeofday(): %s\n", strerror(errno)); |
1220 |
/* Check if we need to send SSDP NOTIFY messages and do it if |
1221 |
/* Check if we need to send SSDP NOTIFY messages and do it if |
1221 |
* needed */ |
1222 |
* needed */ |
1222 |
tv = lastnotifytime; |
1223 |
tv = lastnotifytime; |
Lines 1230-1270
main(int argc, char **argv)
Link Here
|
1230 |
runtime_vars.port, runtime_vars.notify_interval); |
1231 |
runtime_vars.port, runtime_vars.notify_interval); |
1231 |
} |
1232 |
} |
1232 |
lastnotifytime = timeofday; |
1233 |
lastnotifytime = timeofday; |
1233 |
timeout = runtime_vars.notify_interval * 1000; |
1234 |
tv.tv_sec = runtime_vars.notify_interval; |
|
|
1235 |
tv.tv_usec = 0; |
1234 |
} |
1236 |
} |
1235 |
else |
1237 |
else |
1236 |
{ |
1238 |
{ |
1237 |
timevalsub(&tv, &timeofday); |
1239 |
timevalsub(&tv, &timeofday); |
1238 |
timeout = tv.tv_sec * 1000 + tv.tv_usec / 1000; |
|
|
1239 |
} |
1240 |
} |
1240 |
#ifdef TIVO_SUPPORT |
1241 |
#ifdef TIVO_SUPPORT |
1241 |
if (sbeacon >= 0) |
1242 |
if (sbeacon >= 0) |
1242 |
{ |
1243 |
{ |
1243 |
u_long beacontimeout; |
1244 |
struct timeval beacontv; |
1244 |
|
1245 |
|
1245 |
tv = lastbeacontime; |
1246 |
beacontv = lastbeacontime; |
1246 |
tv.tv_sec += beacon_interval; |
1247 |
beacontv.tv_sec += beacon_interval; |
1247 |
if (timevalcmp(&timeofday, &tv, >=)) |
1248 |
if (timevalcmp(&timeofday, &beacontv, >=)) |
1248 |
{ |
1249 |
{ |
1249 |
sendBeaconMessage(sbeacon, &tivo_bcast, sizeof(struct sockaddr_in), 1); |
1250 |
sendBeaconMessage(sbeacon, &tivo_bcast, sizeof(struct sockaddr_in), 1); |
1250 |
lastbeacontime = timeofday; |
1251 |
lastbeacontime = timeofday; |
1251 |
beacontimeout = beacon_interval * 1000; |
|
|
1252 |
if (timeout > beacon_interval * 1000) |
1253 |
timeout = beacon_interval * 1000; |
1254 |
/* Beacons should be sent every 5 seconds or |
1252 |
/* Beacons should be sent every 5 seconds or |
1255 |
* so for the first minute, then every minute |
1253 |
* so for the first minute, then every minute |
1256 |
* or so thereafter. */ |
1254 |
* or so thereafter. */ |
1257 |
if (beacon_interval == 5 && (timeofday.tv_sec - startup_time) > 60) |
1255 |
if (beacon_interval == 5 && (timeofday.tv_sec - startup_time) > 60) |
1258 |
beacon_interval = 60; |
1256 |
beacon_interval = 60; |
|
|
1257 |
beacontv.tv_sec = beacon_interval; |
1258 |
beacontv.tv_usec = 0; |
1259 |
} |
1259 |
} |
1260 |
else |
1260 |
else |
1261 |
{ |
1261 |
{ |
1262 |
timevalsub(&tv, &timeofday); |
1262 |
timevalsub(&beacontv, &timeofday); |
1263 |
beacontimeout = tv.tv_sec * 1000 + |
|
|
1264 |
tv.tv_usec / 1000; |
1265 |
} |
1263 |
} |
1266 |
if (timeout > beacontimeout) |
1264 |
if (timevalcmp(&tv, &beacontv, >)) |
1267 |
timeout = beacontimeout; |
1265 |
tv = beacontv; |
1268 |
} |
1266 |
} |
1269 |
#endif |
1267 |
#endif |
1270 |
|
1268 |
|
Lines 1279-1291
main(int argc, char **argv)
Link Here
|
1279 |
#endif |
1277 |
#endif |
1280 |
} else |
1278 |
} else |
1281 |
/* Keep checking for the scanner every sec. */ |
1279 |
/* Keep checking for the scanner every sec. */ |
1282 |
timeout = 1000; |
1280 |
tv.tv_sec = 1; |
1283 |
} |
1281 |
} |
1284 |
|
1282 |
|
1285 |
event_module.process(timeout); |
1283 |
event_module.process(&tv); |
1286 |
if (quitting) |
1284 |
if (quitting) |
1287 |
goto shutdown; |
1285 |
goto shutdown; |
1288 |
|
1286 |
|
|
|
1287 |
if (gettimeofday(&timeofday, 0) < 0) |
1288 |
DPRINTF(E_FATAL, L_GENERAL, "gettimeofday(): %s\n", strerror(errno)); |
1289 |
|
1289 |
upnpevents_gc(); |
1290 |
upnpevents_gc(); |
1290 |
|
1291 |
|
1291 |
/* increment SystemUpdateID if the content database has changed, |
1292 |
/* increment SystemUpdateID if the content database has changed, |