From 625cbad4e83d2c97b1368cb7f8e5476766309984 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Tue, 23 Jan 2007 16:42:13 +0000 Subject: [PATCH] Return FD task pointer if already added with same fd and is still valid task. --- lib/silcutil/silcschedule.c | 6 ++---- lib/silcutil/silcschedule.h | 7 +++++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/silcutil/silcschedule.c b/lib/silcutil/silcschedule.c index 5d1760cc..aa0e9eb5 100644 --- a/lib/silcutil/silcschedule.c +++ b/lib/silcutil/silcschedule.c @@ -601,10 +601,8 @@ SilcTask silc_schedule_task_add(SilcSchedule schedule, SilcUInt32 fd, if (silc_unlikely(silc_hash_table_find(schedule->fd_queue, SILC_32_TO_PTR(fd), NULL, (void **)&task))) { - if (task->valid) { - task = NULL; + if (task->valid) goto out; - } /* Remove invalid task. We must have unique fd key to hash table. */ silc_schedule_task_remove(schedule, task); @@ -640,7 +638,7 @@ SilcTask silc_schedule_task_add(SilcSchedule schedule, SilcUInt32 fd, task = NULL; goto out; } - if (!schedule_ops.schedule_fd(schedule, schedule->internal, + if (!schedule_ops.schedule_fd(schedule, schedule->internal, ftask, ftask->events)) { silc_hash_table_del(schedule->fd_queue, SILC_32_TO_PTR(fd)); task = NULL; diff --git a/lib/silcutil/silcschedule.h b/lib/silcutil/silcschedule.h index 32557df9..dff50dfc 100644 --- a/lib/silcutil/silcschedule.h +++ b/lib/silcutil/silcschedule.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1998 - 2006 Pekka Riikonen + Copyright (C) 1998 - 2007 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -378,6 +378,9 @@ void *silc_schedule_get_context(SilcSchedule schedule); * The task will be initially set for SILC_TASK_READ events. Setting that * event immediately after this call returns is not necessary. * + * This returns the new task or NULL on error. If a task with `fd' has + * already been added this will return the existing task pointer. + * ***/ #define silc_schedule_task_add_fd(schedule, fd, callback, context) \ silc_schedule_task_add(schedule, fd, callback, context, 0, 0, SILC_TASK_FD) @@ -533,7 +536,7 @@ void silc_schedule_task_del_by_all(SilcSchedule schedule, int fd, * * SYNOPSIS * - * SilcBool silc_schedule_set_listen_fd(SilcSchedule schedule, + * SilcBool silc_schedule_set_listen_fd(SilcSchedule schedule, * SilcUInt32 fd, * SilcTaskEvent mask, * SilcBool send_events); -- 2.24.0