Return FD task pointer if already added with same fd and is still
authorPekka Riikonen <priikone@silcnet.org>
Tue, 23 Jan 2007 16:42:13 +0000 (16:42 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 23 Jan 2007 16:42:13 +0000 (16:42 +0000)
valid task.

lib/silcutil/silcschedule.c
lib/silcutil/silcschedule.h

index 5d1760cc150320a26323647f83b4cc94a86fcf66..aa0e9eb5c7d218221d38d1bd2f7e08746293842c 100644 (file)
@@ -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;
index 32557df955290a00467e7526e0335d35e56ee23b..dff50dfc870799042f2432b129e2ae10f5475d66 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  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);