110 {
113
114 int lst = socket(AF_INET, SOCK_STREAM, 0);
115 struct sockaddr_in a = {.sin_family = AF_INET};
116 a.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
117 if (lst < 0 || bind(lst, (struct sockaddr *)&a, sizeof(a)) != 0 || listen(lst, 4) != 0) {
118 perror("listener setup");
119 return 1;
120 }
122 socklen_t al = sizeof(a);
123 if (getsockname(lst, (struct sockaddr *)&a, &al) != 0) {
124 perror("getsockname");
125 return 1;
126 }
127
132
134 close(lst);
135
138 return 0;
139}
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...