From patchwork Fri Feb 1 12:24:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pontus Fuchs X-Patchwork-Id: 217445 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) by ozlabs.org (Postfix) with ESMTP id 8AD0D2C007C for ; Fri, 1 Feb 2013 23:24:59 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 4AF339D238; Fri, 1 Feb 2013 07:24:56 -0500 (EST) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dm8mFwiQuerX; Fri, 1 Feb 2013 07:24:56 -0500 (EST) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 9A2289D23E; Fri, 1 Feb 2013 07:24:44 -0500 (EST) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 57D469D23E for ; Fri, 1 Feb 2013 07:24:43 -0500 (EST) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id facCzH0EqEg0 for ; Fri, 1 Feb 2013 07:24:39 -0500 (EST) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com [209.85.215.48]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id 6ADE59D238 for ; Fri, 1 Feb 2013 07:24:39 -0500 (EST) Received: by mail-la0-f48.google.com with SMTP id fq13so2710344lab.21 for ; Fri, 01 Feb 2013 04:24:37 -0800 (PST) X-Received: by 10.152.123.194 with SMTP id mc2mr10649375lab.7.1359721477775; Fri, 01 Feb 2013 04:24:37 -0800 (PST) Received: from localhost.localdomain (host-95-195-141-132.mobileonline.telia.com. [95.195.141.132]) by mx.google.com with ESMTPS id pz15sm4032067lab.3.2013.02.01.04.24.35 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 01 Feb 2013 04:24:37 -0800 (PST) From: Pontus Fuchs To: hostap@lists.shmoo.com Subject: [PATCH 1/2] eloop: Add a timer cancel that returns the remaining time Date: Fri, 1 Feb 2013 13:24:21 +0100 Message-Id: <1359721462-3780-2-git-send-email-pontus.fuchs@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1359721462-3780-1-git-send-email-pontus.fuchs@gmail.com> References: <1359721462-3780-1-git-send-email-pontus.fuchs@gmail.com> X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com This new cancel timer will give back the remaining time if it was pending. Signed-hostap: Pontus Fuchs --- src/utils/eloop.c | 27 +++++++++++++++++++++++++++ src/utils/eloop.h | 15 +++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/utils/eloop.c b/src/utils/eloop.c index d01ae64..8ee4fec 100644 --- a/src/utils/eloop.c +++ b/src/utils/eloop.c @@ -556,6 +556,33 @@ int eloop_cancel_timeout(eloop_timeout_handler handler, } +int eloop_cancel_timeout_one(eloop_timeout_handler handler, + void *eloop_data, void *user_data, + struct os_time *remaining) +{ + struct eloop_timeout *timeout, *prev; + int removed = 0; + struct os_time now; + + os_get_time(&now); + remaining->sec = remaining->usec = 0; + + dl_list_for_each_safe(timeout, prev, &eloop.timeout, + struct eloop_timeout, list) { + if (timeout->handler == handler && + (timeout->eloop_data == eloop_data) && + (timeout->user_data == user_data)) { + removed = 1; + if (os_time_before(&now, &timeout->time)) + os_time_sub(&timeout->time, &now, remaining); + eloop_remove_timeout(timeout); + break; + } + } + return removed; +} + + int eloop_is_timeout_registered(eloop_timeout_handler handler, void *eloop_data, void *user_data) { diff --git a/src/utils/eloop.h b/src/utils/eloop.h index db03a73..53f5d39 100644 --- a/src/utils/eloop.h +++ b/src/utils/eloop.h @@ -195,6 +195,21 @@ int eloop_cancel_timeout(eloop_timeout_handler handler, void *eloop_data, void *user_data); /** + * eloop_cancel_timeout_one - Cancel a single timeout + * @handler: Matching callback function + * @eloop_data: Matching eloop_data + * @user_data: Matching user_data + * @remaining: Time left on the cancelled timer + * Returns: Number of cancelled timeouts + * + * Cancel matching timeout registered with + * eloop_register_timeout() and return the remaining time left in remaining. + */ +int eloop_cancel_timeout_one(eloop_timeout_handler handler, + void *eloop_data, void *user_data, + struct os_time *remaining); + +/** * eloop_is_timeout_registered - Check if a timeout is already registered * @handler: Matching callback function * @eloop_data: Matching eloop_data