52 int fl = fcntl(fd, F_GETFL, 0);
53 (void)fcntl(fd, F_SETFL, fl | O_NONBLOCK);
61 printf(
"writer: error: %s\n", r.maybe_error->msg);
63 printf(
"writer: wrote %zu bytes\n", r.
count);
74 printf(
"reader: error: %s\n", r.maybe_error->msg);
77 printf(
"reader: read %zu bytes: \"%s\"\n", r.
count, rd->
buf);
static void set_nonblock(int fd)
static srn_fiber_result_t writer(srn_context_t *ctx, void *arg)
static srn_fiber_result_t reader(srn_context_t *ctx, void *arg)
srn_context_t * srn_context_make(srn_engine_t *engine)
Make an empty context, by allocating a new memory block.
int srn_context_release(srn_context_t *ctx)
#define HAS_ERROR(x)
True when x – a value carrying an ERROR_HEADER – has an error attached.
srn_fiber_t * srn_fiber_spawn(srn_context_t *ctx, srn_fiber_entry_t entry, void *arg)
Make and schedule a fiber with every default, the engine's scheduler, the configured stack size,...
void * srn_fiber_result_t
What a fiber's entry produces, type-erased.
srn_io_size_result_t srn_fiber_write(int fd, const void *buf, size_t len, int64_t offset)
Write len bytes from buf to fd, suspending the calling fiber until the operation completes rather tha...
srn_io_size_result_t srn_fiber_read(int fd, void *buf, size_t len, int64_t offset)
Read up to len bytes from fd into buf, suspending the calling fiber until the operation completes rat...
The fiber facing IO API: blocking looking calls a fiber uses to do IO.
#define SERENE_RUNTIME_SHUTDOWN(engine)
Tear down what SERENE_RUNTIME_INIT brought up, in reverse order, the engine (reactor,...
#define SERENE_RUNTIME_INIT_WITH_SCHED(engine, sched, config)
SERENE_RUNTIME_INIT plus a sched variable bound to the engine's scheduler, which every run and fiber ...
void srn_sched_run(srn_scheduler_t *sched, size_t nworkers)
Run the scheduler with nworkers os threads draining it, returning once the pool goes quiescent (every...
The result of a byte transfer op (read/write/sendto/recvmsg/sendmsg).