Closing the socket from the main thread, while the server thread is
still in accept() (or is just about to enter it), seems to
occasionally cause a deadlock on macOS.
if (server_config)
{
shutdown(server_config->fd, SHUT_RDWR);
- close(server_config->fd);
free(server_config);
server_config = NULL;
}
}
END_TEARDOWN
+static void close_fd_ptr(void *fd)
+{
+ close(*(int*)fd);
+}
+
/**
* Run an echo server
*/
}
sfd = config->fd;
thread_cleanup_push((thread_cleanup_t)server->destroy, server);
+ thread_cleanup_push(close_fd_ptr, &sfd);
while (TRUE)
{
oldstate = thread_cancelability(TRUE);
close(cfd);
}
thread_cleanup_pop(TRUE);
+ thread_cleanup_pop(TRUE);
return JOB_REQUEUE_NONE;
}