kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit c5fe59f521bdc1f2c486b5d8cc90227d72fcc628
parent 315c5085b79c067358960f4b88bc5136999edfe3
Author: Joris Vink <joris@sanctorum.se>
Date:   Wed,  4 Nov 2026 18:01:55 +0100

Add kore_task_channel_pending().

Called if you want to test if more events are pending
on a task that can be read.

Diffstat:
include/kore/tasks.h | 1+
src/tasks.c | 26++++++++++++++++++++++++++
2 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/include/kore/tasks.h b/include/kore/tasks.h @@ -80,6 +80,7 @@ void kore_task_bind_callback(struct kore_task *, void kore_task_create(struct kore_task *, int (*entry)(struct kore_task *)); +int kore_task_channel_pending(struct kore_task *); u_int32_t kore_task_channel_read(struct kore_task *, void *, u_int32_t); void kore_task_channel_write(struct kore_task *, void *, u_int32_t); diff --git a/src/tasks.c b/src/tasks.c @@ -19,6 +19,7 @@ #include <sys/socket.h> #include <pthread.h> +#include <poll.h> #include <stdio.h> #include <stdlib.h> @@ -184,6 +185,31 @@ kore_task_finish(struct kore_task *t) pthread_rwlock_unlock(&(t->lock)); } +int +kore_task_channel_pending(struct kore_task *t) +{ + struct pollfd pfd; + + THREAD_FD_ASSIGN(t->thread->tid, pfd.fd, t->fds[1], t->fds[0]); + + pfd.events = POLLIN; + + for (;;) { + if (poll(&pfd, 1, 0) == -1) { + if (errno == EINTR) + continue; + fatal("poll: %s", errno_s); + } + + break; + } + + if (pfd.revents & POLLIN) + return (1); + + return (0); +} + void kore_task_channel_write(struct kore_task *t, void *data, u_int32_t len) {