From 16e2b0213b54991d9f493d4c0ee7efca18436427 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 18 Nov 2015 01:23:21 +0100 Subject: Clean up peer task handling --- src/peer.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/peer.c') diff --git a/src/peer.c b/src/peer.c index 9f26803..22339b4 100644 --- a/src/peer.c +++ b/src/peer.c @@ -364,13 +364,21 @@ void fastd_peer_handle_resolve(fastd_peer_t *peer, fastd_remote_t *remote, size_ init_handshake(peer); } -/** Schedules the peer maintenance task (or removes the schduled task if there's nothing to do) */ -void schedule_peer_task(fastd_peer_t *peer) { - fastd_task_unschedule(&peer->task); - +/** Schedules the peer maintenance task (or removes the scheduled task if there's nothing to do) */ +static void schedule_peer_task(fastd_peer_t *peer) { fastd_timeout_t timeout = fastd_timeout_min(peer->reset_timeout, peer->keepalive_timeout); - if (timeout != fastd_timeout_inv) + if (timeout == fastd_timeout_inv) { + pr_debug2("Removing scheduled task for %P", peer); + fastd_task_unschedule(&peer->task); + } + else if (fastd_task_timeout(&peer->task) > timeout) { + pr_debug2("Replacing scheduled task for %P", peer); + fastd_task_unschedule(&peer->task); fastd_task_schedule(&peer->task, TASK_TYPE_PEER, timeout); + } + else { + pr_debug2("Keeping scheduled task for %P", peer); + } } /** Initializes a peer */ -- cgit v1.2.3