105 {
108
109 int one = 1;
110 int sock = socket(AF_INET, SOCK_STREAM, 0);
111 setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(int));
112
113 int port = 8080;
114 struct sockaddr_in a = {
115 .sin_family = AF_INET,
116 .sin_addr = {INADDR_ANY},
117 .sin_port = htons(port),
118 };
119
120 if (sock < 0 || bind(sock, (struct sockaddr *)&a, sizeof(a)) != 0 || listen(sock, 128) != 0) {
121 perror("listener setup");
122 return 1;
123 }
124
126 socklen_t al = sizeof(a);
127 if (getsockname(sock, (struct sockaddr *)&a, &al) != 0) {
128 perror("getsockname");
129 return 1;
130 }
131
132 printf("Running the webserver on 0.0.0.0:%d\n", port);
135
137 close(sock);
138
141 return 0;
142}
static srn_fiber_result_t server(srn_context_t *ctx, void *arg)
static void set_nonblock(int fd)
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...