Ejemplo n.º 1
0
/* Timer callback for @periodic_save_timer.  As explained in @install_timer,
 * this function must erase the expired timer ID from all variables.  */
static void
periodic_save_handler(void *xxx)
{
	static int periodic_save_event_id = EVENT_NONE;
	milliseconds_T interval;

	if (get_cmd_opt_bool((const unsigned char *)"anonymous")) return;

	/* Don't trigger anything at startup */
	if (periodic_save_event_id == EVENT_NONE)
		set_event_id(periodic_save_event_id, (unsigned char *)"periodic-saving");
	else
		trigger_event(periodic_save_event_id);

	interval = sec_to_ms(get_opt_int((const unsigned char *)"infofiles.save_interval", NULL));
	if (!interval) {
		/* We should get here only if @periodic_save_handler
		 * is being called from @periodic_save_change_hook or
		 * @init_timer, rather than from the timer system.  */
		assert(periodic_save_timer == TIMER_ID_UNDEF);
		return;
	}

	install_timer(&periodic_save_timer, interval, periodic_save_handler, NULL);
	/* The expired timer ID has now been erased.  */
}
Ejemplo n.º 2
0
/* The timeout mechanism is used for both inactive incoming peer connections
 * and peer connections attached to a BitTorrent (master) connection. */
void
set_bittorrent_peer_connection_timeout(struct bittorrent_peer_connection *peer)
{
	milliseconds_T timeout = sec_to_ms(get_opt_int("protocol.bittorrent.peerwire.timeout", NULL));

	kill_timer(&peer->timer);
	install_timer(&peer->timer, timeout,
		      (void (*)(void *)) bittorrent_peer_connection_timeout,
		      peer);
}