diff --git a/lib_fiber/c/src/common/timer_cache.c b/lib_fiber/c/src/common/timer_cache.c index c2df38dce..255323b8d 100644 --- a/lib_fiber/c/src/common/timer_cache.c +++ b/lib_fiber/c/src/common/timer_cache.c @@ -106,7 +106,7 @@ int timer_cache_remove(TIMER_CACHE *cache, long long expire, RING *entry) } if (entry->parent != &node->ring) { - // Maybe the fiber has been append to the other ring. + // Maybe the fiber has been appended to the other ring. if (ring_size(&node->ring) == 0) { timer_cache_free_node(cache, node); } @@ -128,7 +128,7 @@ void timer_cache_free_node(TIMER_CACHE *cache, TIMER_CACHE_NODE *node) // The node will be removed if it hasn't any entry. fiber_avl_remove(&cache->tree, node); - // The node object can be cached for being reused in future. + // The node object can be cached for being reused in the future. if (cache->cache_max > 0 && ring_size(&cache->caches) < cache->cache_max) { ring_append(&cache->caches, &node->ring); } else { diff --git a/lib_fiber/c/src/event.c b/lib_fiber/c/src/event.c index 8d81c08f9..9cf0e8882 100644 --- a/lib_fiber/c/src/event.c +++ b/lib_fiber/c/src/event.c @@ -128,7 +128,37 @@ long long event_get_stamp(EVENT *ev) return ev->stamp; } -#ifdef SYS_WIN +#if defined(USE_FSTAT_CHECKFD) +int event_checkfd(EVENT *ev fiber_unused, FILE_EVENT *fe) +{ + struct stat buf; + + if (fstat(fe->fd, &buf) == -1) { + msg_error("%s(%d): fstat error=%s, fd=%d", + __FUNCTION__, __LINE__, last_serror(), fe->fd); + acl_fiber_set_error(errno); + fe->type = TYPE_BADFD; + return -1; + } + + if (S_ISCHR(buf.st_mode) || S_ISFIFO(buf.st_mode) + || S_ISSOCK(buf.st_mode)) { + fe->type = TYPE_SPIPE | TYPE_EVENTABLE; + acl_fiber_set_error(0); + return 1; +# if defined(HAS_IO_URING) + } else if (EVENT_IS_IO_URING(ev)) { + fe->type = TYPE_FILE | TYPE_EVENTABLE; + acl_fiber_set_error(0); + return 1; +# endif + } else { + fe->type = TYPE_FILE; + acl_fiber_set_error(0); + return 0; + } +} +#elif defined(SYS_WIN) int event_checkfd(EVENT *ev, FILE_EVENT *fe) { if (getsockfamily(fe->fd) >= 0) { diff --git a/lib_fiber/c/src/fiber_io.c b/lib_fiber/c/src/fiber_io.c index 0afa9707c..52858f2f9 100644 --- a/lib_fiber/c/src/fiber_io.c +++ b/lib_fiber/c/src/fiber_io.c @@ -7,7 +7,6 @@ #include "common/timer_cache.h" #include "event.h" #include "hook/hook.h" -#include "hook/io.h" #include "fiber.h" typedef struct { @@ -178,7 +177,7 @@ void fiber_timer_add(ACL_FIBER *fiber, size_t milliseconds) long long now = event_get_stamp(ev); TIMER_CACHE_NODE *timer; - fiber->when = now + milliseconds; + fiber->when = now + (ssize_t) milliseconds; ring_detach(&fiber->me); // Detch the previous binding. timer_cache_add(__thread_fiber->ev_timer, fiber->when, &fiber->me); @@ -224,7 +223,7 @@ static void wakeup_timers(TIMER_CACHE *timers, long long now) // timer's arriving. fb->flag |= FIBER_F_TIMER; - // The fb->me was be appended in fiber_timer_add, and + // The fb->me was appended in fiber_timer_add, and // we detatch fb->me from timer node and append it to // the ready ring in acl_fiber_ready. ring_detach(&fb->me); @@ -282,9 +281,7 @@ static void fiber_io_loop(ACL_FIBER *self fiber_unused, void *ctx) */ while (acl_fiber_yield() > 0) {} - if (ev->waiter > 0) { - continue; - } else if (ring_size(&ev->events) > 0) { + if (ev->waiter > 0 || ring_size(&ev->events) > 0) { continue; } @@ -359,7 +356,7 @@ size_t acl_fiber_delay(size_t milliseconds) fiber->flag &= ~FIBER_F_TIMER; if (acl_fiber_killed(fiber)) { - // If been killed, the fiber must has been detatched from the + // If been killed, the fiber must have been detatched from the // timer node in acl_fiber_signal(); We call fiber_timer_del // here in order to try to free the timer node. fiber_timer_del(fiber); @@ -418,7 +415,7 @@ ACL_FIBER *acl_fiber_create_timer(size_t milliseconds, size_t size, fiber_io_check(); when = fiber_io_stamp(); - when += milliseconds; + when += (ssize_t) milliseconds; fiber = acl_fiber_create(fiber_timer_callback, tc, size); fiber->when = when; diff --git a/lib_fiber/c/src/hook/poll.c b/lib_fiber/c/src/hook/poll.c index 19b45f611..e68b13d35 100644 --- a/lib_fiber/c/src/hook/poll.c +++ b/lib_fiber/c/src/hook/poll.c @@ -366,7 +366,7 @@ int WINAPI acl_fiber_poll(struct pollfd *fds, nfds_t nfds, int timeout) pe->fds = pollfd_alloc(pe, fds, nfds); #endif - pe->nfds = nfds; + pe->nfds = (int) nfds; pe->fiber = curr; pe->proc = poll_callback; diff --git a/lib_fiber/c/src/stdafx.h b/lib_fiber/c/src/stdafx.h index 2cf55b67f..451f25ea2 100644 --- a/lib_fiber/c/src/stdafx.h +++ b/lib_fiber/c/src/stdafx.h @@ -14,7 +14,7 @@ #endif #ifndef _GNU_SOURCE -#define _GNU_SOURCE +# define _GNU_SOURCE #endif #include @@ -55,6 +55,7 @@ #define STRDUP strdup #define GETPID getpid +#define USE_FSTAT_CHECKFD #elif defined(SYS_WIN)