MCPcopy Create free account
hub / github.com/antirez/ds4 / dist_coordinator_accept_main

Function dist_coordinator_accept_main

ds4_distributed.c:4280–4323  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4278}
4279
4280static void *dist_coordinator_accept_main(void *arg) {
4281 ds4_dist_accept_ctx *accept_ctx = arg;
4282 int listen_fd = accept_ctx->listen_fd;
4283 ds4_dist_coordinator_state *state = accept_ctx->state;
4284
4285 for (;;) {
4286 struct sockaddr_storage ss;
4287 socklen_t slen = sizeof(ss);
4288 int fd = accept(listen_fd, (struct sockaddr *)&ss, &slen);
4289 if (fd < 0) {
4290 if (errno == EINTR) continue;
4291 if (errno == EBADF || errno == EINVAL) break;
4292 DIST_COORD_DEBUG(state, "ds4: distributed coordinator: accept failed: %s\n", strerror(errno));
4293 continue;
4294 }
4295 dist_set_socket_low_latency(fd);
4296
4297 ds4_dist_client_ctx *ctx = calloc(1, sizeof(*ctx));
4298 if (!ctx) {
4299 DIST_COORD_DEBUG(state, "ds4: distributed coordinator: out of memory accepting worker\n");
4300 close(fd);
4301 continue;
4302 }
4303 ctx->state = state;
4304 ctx->fd = fd;
4305 if (getnameinfo((struct sockaddr *)&ss, slen,
4306 ctx->peer_host, sizeof(ctx->peer_host),
4307 ctx->peer_port, sizeof(ctx->peer_port),
4308 NI_NUMERICHOST | NI_NUMERICSERV) != 0) {
4309 snprintf(ctx->peer_host, sizeof(ctx->peer_host), "unknown");
4310 snprintf(ctx->peer_port, sizeof(ctx->peer_port), "0");
4311 }
4312
4313 pthread_t tid;
4314 if (pthread_create(&tid, NULL, dist_coordinator_client_main, ctx) != 0) {
4315 DIST_COORD_DEBUG(state, "ds4: distributed coordinator: pthread_create failed\n");
4316 close(fd);
4317 free(ctx);
4318 continue;
4319 }
4320 pthread_detach(tid);
4321 }
4322 return NULL;
4323}
4324
4325static uint64_t dist_make_session_id(const void *ptr) {
4326 uint64_t id = ((uint64_t)(uint32_t)time(NULL) << 32) ^ (uint64_t)getpid();

Callers 1

dist_run_coordinatorFunction · 0.85

Calls 1

Tested by

no test coverage detected