Пример #1
0
/* Time out handler of SSDP, GEAN and all the devices */
void
upnp_timeout(UPNP_CONTEXT *context)
{
	UPNP_INTERFACE	*ifp;
	UPNP_DEVICE	*device;

	time_t now = time(0);
	int update_ssdp;
	int update_gena;
	int delta;

	/* Special patch for NTP */
	if ((now - context->upnp_last_time) > 631123200) {
		/* Update for ssdp */
		delta = context->upnp_last_time - context->adv_seconds;
		context->adv_seconds = (now - delta) - 1;
	}

	/* Okay, it's safe to check */
	update_ssdp = ((u_long)(now - context->adv_seconds) >= context->adv_time - 1);
	update_gena = ((u_long)(now - context->gena_last_check) >= GENA_TIMEOUT);

	/* Add device timer here */
	for (ifp = context->iflist;
		 ifp;
		 ifp = ifp->next) {

		/* Set the focus inteface for further reference */
		context->focus_ifp = ifp;

		/* check for advertisement interval */
		if (update_ssdp)
			ssdp_timeout(context);

		/* check for subscription expirations every 30 seconds */
		if (update_gena)
			gena_timeout(context);

		/* Check device timeout */
		device = ifp->device;
		if (device && device->timeout)
			(*device->timeout)(context, now);
	}

	/* Update ssdp timer, gena timer, and current system time */
	if (update_ssdp)
		context->adv_seconds = now;

	if (update_gena)
		context->gena_last_check = now;

	context->upnp_last_time = now;
	return;
}
Пример #2
0
/* Time out handler of SSDP, GEAN and all the devices */
void
upnp_timeout(UPNP_CONTEXT *context)
{
	UPNP_INTERFACE	*ifp;
	UPNP_DEVCHAIN	*chain;

	time_t now = time(0);
	int	update_ssdp = ((u_long)(now - context->adv_seconds) > context->config.adv_time);
	int update_gena = ((u_long)(now - context->gena_last_check) >= GENA_TIMEOUT);

	/* Add device timer here */
	for (ifp = context->iflist;
		 ifp;
		 ifp = ifp->next) {

		/* Set the focus inteface for further reference */
		context->focus_ifp = ifp;

		/* loop for each device to check timeout */
		for (chain = ifp->device_chain;
			 chain;
			 chain = chain->next) {

			ifp->focus_devchain = chain;

			/* check for advertisement interval */
			if (update_ssdp)
				ssdp_timeout(context);

			/* check for subscription expirations every 30 seconds */
			if (update_gena)
				gena_timeout(context);

			/* Check device timeout */
			if (chain->device->timeout)
				(*chain->device->timeout)(context, now);
		}
	}

	/* Update ssdp timer and gena timer */
	if (update_ssdp)
		context->adv_seconds = now;

	if (update_gena)
		context->gena_last_check = now;

	return;
}