122 {
125
126 int lst = socket(AF_INET, SOCK_STREAM, 0);
127 struct sockaddr_in a = {.sin_family = AF_INET};
128 a.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
129 if (lst < 0 || bind(lst, (struct sockaddr *)&a, sizeof(a)) != 0 || listen(lst, 4) != 0) {
130 perror("listener setup");
131 return 1;
132 }
134 socklen_t al = sizeof(a);
135 if (getsockname(lst, (struct sockaddr *)&a, &al) != 0) {
136 perror("getsockname");
137 return 1;
138 }
139
144
146 close(lst);
147
150 return 0;
151}
static srn_fiber_result_t client(srn_context_t *ctx, void *arg)
static srn_fiber_result_t server(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)
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,...
#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...