DskDispatchTimer *dsk_main_add_timer_millis(unsigned milliseconds, DskTimerFunc func, void *func_data) { return dsk_dispatch_add_timer_millis (dsk_dispatch_default (), milliseconds, func, func_data); }
static void maybe_set_autoreconnect_timer (DskClientStream *stream) { dsk_assert (stream->reconnect_timer == NULL); if (stream->reconnect_time_ms >= 0) stream->reconnect_timer = dsk_dispatch_add_timer_millis (dsk_dispatch_default (), stream->reconnect_time_ms, handle_reconnect_timer_expired, stream); }
static void handle_fd_connected (DskClientStream *stream) { stream_do_watch_fd (stream); dsk_assert (stream->idle_disconnect_timer == NULL); if (stream->idle_disconnect_time_ms >= 0) stream->idle_disconnect_timer = dsk_dispatch_add_timer_millis (dsk_dispatch_default (), stream->idle_disconnect_time_ms, handle_idle_too_long, stream); }
/* use -1 to disable these timeouts */ void dsk_client_stream_set_reconnect_time (DskClientStream *client, int millis) { /* short-circuit no-op cases */ if (millis < 0) { if (client->reconnect_time_ms == -1) return; millis = -1; } else if (client->reconnect_time_ms == millis) return; /* if we have a valid file-descriptor or we are resolving the name, there then the reconnect_time_ms is not currently relevant: set it and go */ if (client->fd != -1 || client->is_resolving_name) { client->reconnect_time_ms = millis; return; } if (millis == -1) { /* handle timer removal */ if (client->reconnect_timer) { dsk_dispatch_remove_timer (client->reconnect_timer); client->reconnect_timer = NULL; } else dsk_warn_if_reached ("no reconnect timer?"); } else { if (client->reconnect_time_ms >= 0) dsk_dispatch_remove_timer (client->reconnect_timer); else dsk_assert (client->reconnect_timer == NULL); client->reconnect_time_ms = millis; /* TODO: subtract elapsed time from last disconnect / failed to connect */ client->reconnect_timer = dsk_dispatch_add_timer_millis (dsk_dispatch_default (), millis, handle_reconnect_timer_expired, client); } }
void dsk_client_stream_set_max_idle_time (DskClientStream *client, int millis) { if (millis < 0) millis = -1; if (millis == client->idle_disconnect_time_ms) return; if (client->idle_disconnect_timer != NULL) { dsk_dispatch_remove_timer (client->idle_disconnect_timer); client->idle_disconnect_timer = NULL; } if (millis >= 0 && client->is_connected) client->idle_disconnect_timer = dsk_dispatch_add_timer_millis (dsk_dispatch_default (), millis, handle_idle_too_long, client); client->idle_disconnect_time_ms = millis; }