--- libaitsched/src/hooks.c 2014/01/28 12:14:20 1.24.4.6 +++ libaitsched/src/hooks.c 2014/02/01 14:06:08 1.26.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: hooks.c,v 1.24.4.6 2014/01/28 12:14:20 misho Exp $ +* $Id: hooks.c,v 1.26.2.1 2014/02/01 14:06:08 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 +Copyright 2004 - 2014 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -270,7 +270,7 @@ sched_hook_cancel(void *task, void *arg __unused) pthread_cancel((pthread_t) TASK_VAL(t)); #endif return NULL; -#if defined(HAVE_TIMER_CREATE) && defined(HAVE_TIMER_SETTIME) +#if defined(HAVE_TIMER_CREATE) && defined(HAVE_TIMER_SETTIME) && defined(HAVE_TIMER_DELETE) case taskRTC: timer_delete((timer_t) TASK_FLAG(t)); schedCancel((sched_task_t*) TASK_RET(t)); @@ -638,9 +638,10 @@ sched_hook_fetch(void *root, void *arg __unused) struct timespec now, m, mtmp; #ifndef KQ_DISABLE struct kevent evt[1], res[KQ_EVENTS]; - struct timespec *timeout, m, mtmp; + struct timespec *timeout; #else struct timeval *timeout, tv; + fd_set rfd, wfd, xfd; #endif register int i, flg; int en; @@ -753,8 +754,9 @@ sched_hook_fetch(void *root, void *arg __unused) #ifndef KQ_DISABLE if ((en = kevent(r->root_kq, NULL, 0, res, KQ_EVENTS, timeout)) == -1) { #else - if ((en = select(r->root_kq, &r->root_fds[0], &r->root_fds[1], - &r->root_fds[0], timeout)) == -1) { + rfd = xfd = r->root_fds[0]; + wfd = r->root_fds[1]; + if ((en = select(r->root_kq, &rfd, &wfd, &xfd, timeout)) == -1) { #endif /* KQ_DISABLE */ if (r->root_hooks.hook_exec.exception) { if (r->root_hooks.hook_exec.exception(r, NULL)) @@ -1140,15 +1142,15 @@ sched_hook_fetch(void *root, void *arg __unused) } #else /* end of kevent dispatcher */ for (i = 0; i < r->root_kq; i++) { - if (FD_ISSET(i, &r->root_fds[0])) { + if (FD_ISSET(i, &rfd) || FD_ISSET(i, &xfd)) { flg = 0; TAILQ_FOREACH_SAFE(task, &r->root_read, task_node, tmp) { if (TASK_FD(task) != i) continue; else { flg++; - TASK_RET(task) ^= TASK_RET(task); - TASK_FLAG(task) ^= TASK_FLAG(task); + TASK_FLAG(task) = ioctl(TASK_FD(task), + FIONREAD, &TASK_RET(task)); } /* remove read handle */ #ifdef HAVE_LIBPTHREAD @@ -1194,15 +1196,15 @@ sched_hook_fetch(void *root, void *arg __unused) FD_CLR(i, &r->root_fds[0]); } - if (FD_ISSET(i, &r->root_fds[1])) { + if (FD_ISSET(i, &wfd)) { flg = 0; TAILQ_FOREACH_SAFE(task, &r->root_write, task_node, tmp) { if (TASK_FD(task) != i) continue; else { flg++; - TASK_RET(task) ^= TASK_RET(task); - TASK_FLAG(task) ^= TASK_FLAG(task); + TASK_FLAG(task) = ioctl(TASK_FD(task), + FIONWRITE, &TASK_RET(task)); } /* remove write handle */ #ifdef HAVE_LIBPTHREAD @@ -1385,7 +1387,7 @@ sched_hook_condition(void *root, void *arg) * @arg = unused * return: <0 errors and 0 ok */ -#if defined(HAVE_TIMER_CREATE) && defined(HAVE_TIMER_SETTIME) +#if defined(HAVE_TIMER_CREATE) && defined(HAVE_TIMER_SETTIME) && defined(HAVE_TIMER_DELETE) void * sched_hook_rtc(void *task, void *arg __unused) {