From 4eef3f40d32a4351f65899af80c94492641a64b2 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Fri, 4 May 2012 13:32:08 +0300 Subject: [PATCH] dhcpv6: Refactor timer clearing --- src/dhcpv6.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/dhcpv6.c b/src/dhcpv6.c index 1d1feb2..5d09799 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -74,6 +74,14 @@ static GHashTable *network_table; static int dhcpv6_request(struct connman_dhcpv6 *dhcp, gboolean add_addresses); +static void clear_timer(struct connman_dhcpv6 *dhcp) +{ + if (dhcp->timeout > 0) { + g_source_remove(dhcp->timeout); + dhcp->timeout = 0; + } +} + static inline float get_random() { return (rand() % 200 - 100) / 1000.0; @@ -812,10 +820,7 @@ int __connman_dhcpv6_start_renew(struct connman_network *network, DBG("network %p dhcp %p", network, dhcp); - if (dhcp->timeout > 0) { - g_source_remove(dhcp->timeout); - dhcp->timeout = 0; - } + clear_timer(dhcp); g_dhcpv6_client_get_timeouts(dhcp->dhcp_client, &T1, &T2, &last_renew, &last_rebind, &expired); @@ -886,10 +891,7 @@ int __connman_dhcpv6_start_release(struct connman_network *network, if (dhcp->stateless == TRUE) return -EINVAL; - if (dhcp->timeout > 0) { - g_source_remove(dhcp->timeout); - dhcp->timeout = 0; - } + clear_timer(dhcp); dhcp_client = dhcp->dhcp_client; if (dhcp_client == NULL) { @@ -933,10 +935,7 @@ static int dhcpv6_release(struct connman_dhcpv6 *dhcp) { DBG("dhcp %p", dhcp); - if (dhcp->timeout > 0) { - g_source_remove(dhcp->timeout); - dhcp->timeout = 0; - } + clear_timer(dhcp); dhcpv6_free(dhcp); @@ -1036,10 +1035,7 @@ static void advertise_cb(GDHCPClient *dhcp_client, gpointer user_data) DBG("dhcpv6 advertise msg %p", dhcp); - if (dhcp->timeout > 0) { - g_source_remove(dhcp->timeout); - dhcp->timeout = 0; - } + clear_timer(dhcp); if (g_dhcpv6_client_get_status(dhcp_client) != 0) { if (dhcp->callback != NULL) @@ -1063,10 +1059,7 @@ static void solicitation_cb(GDHCPClient *dhcp_client, gpointer user_data) DBG("dhcpv6 solicitation msg %p", dhcp); - if (dhcp->timeout > 0) { - g_source_remove(dhcp->timeout); - dhcp->timeout = 0; - } + clear_timer(dhcp); set_addresses(dhcp_client, dhcp); } -- 2.7.4