*/
/* $Id$ */
-#include "silcincludes.h"
+#include "silc.h"
/* Platform specific implementation */
extern const SilcScheduleOps schedule_ops;
static void silc_schedule_task_remove(SilcSchedule schedule, SilcTask task);
static void silc_schedule_dispatch_fd(SilcSchedule schedule);
static void silc_schedule_dispatch_timeout(SilcSchedule schedule,
- bool dispatch_all);
+ SilcBool dispatch_all);
/* Fd task hash table destructor */
scheduler could not be uninitialized. This happens when the scheduler
is still valid and silc_schedule_stop has not been called. */
-bool silc_schedule_uninit(SilcSchedule schedule)
+SilcBool silc_schedule_uninit(SilcSchedule schedule)
{
SILC_LOG_DEBUG(("Uninitializing scheduler"));
tasks are removed here. */
static void silc_schedule_dispatch_timeout(SilcSchedule schedule,
- bool dispatch_all)
+ SilcBool dispatch_all)
{
SilcTask t;
SilcTaskTimeout task;
SilcTask t;
SilcTaskTimeout task;
struct timeval curtime;
- bool dispatch = TRUE;
+ SilcBool dispatch = TRUE;
/* Get the current time */
silc_gettimeofday(&curtime);
/* Runs the scheduler once and then returns. */
-bool silc_schedule_one(SilcSchedule schedule, int timeout_usecs)
+SilcBool silc_schedule_one(SilcSchedule schedule, int timeout_usecs)
{
struct timeval timeout;
int ret;
ret = schedule_ops.select(schedule, schedule->internal);
switch (ret) {
+ case 0:
+ /* Timeout */
+ SILC_LOG_DEBUG(("Running timeout tasks"));
+ silc_schedule_dispatch_timeout(schedule, FALSE);
+ break;
case -1:
/* Error */
if (errno == EINTR)
break;
SILC_LOG_ERROR(("Error in select(): %s", strerror(errno)));
break;
- case 0:
- /* Timeout */
- SILC_LOG_DEBUG(("Running timeout tasks"));
- silc_schedule_dispatch_timeout(schedule, FALSE);
- break;
default:
/* There is some data available now */
SILC_LOG_DEBUG(("Running fd tasks"));
if (!ttask)
goto out;
- SILC_LOG_DEBUG(("Registering new timeout task %p", ttask));
-
ttask->header.type = 1;
ttask->header.callback = callback;
ttask->header.context = context;
silc_gettimeofday(&ttask->timeout);
ttask->timeout.tv_sec += seconds + (useconds / 1000000L);
ttask->timeout.tv_usec += (useconds % 1000000L);
- if (ttask->timeout.tv_usec > 999999L) {
+ if (ttask->timeout.tv_usec >= 1000000L) {
ttask->timeout.tv_sec += 1;
ttask->timeout.tv_usec -= 1000000L;
}
}
+ SILC_LOG_DEBUG(("New timeout task %p: sec=%d, usec=%d", ttask,
+ seconds, useconds));
+
/* Add task to correct spot so that the first task in the list has
the earliest timeout. */
silc_list_start(schedule->timeout_queue);
} else {
/* Check if fd is already added */
if (silc_hash_table_find(schedule->fd_queue, SILC_32_TO_PTR(fd),
- NULL, NULL))
+ NULL, (void **)&task))
goto out;
/* Check max tasks */
if (!ftask)
goto out;
- SILC_LOG_DEBUG(("Registering new fd task %p fd=%d", ftask, fd));
+ SILC_LOG_DEBUG(("New fd task %p fd=%d", ftask, fd));
ftask->header.type = 0;
ftask->header.callback = callback;
descriptor to set different iomasks. */
void silc_schedule_set_listen_fd(SilcSchedule schedule, SilcUInt32 fd,
- SilcTaskEvent mask, bool send_events)
+ SilcTaskEvent mask, SilcBool send_events)
{
SilcTaskFd task;