- while (!hupped) {
- // Since we are non-blocking, we need to wait for the right state first.
- // Wait up to 50 ms, then check hupped.
- pollfd pfd;
- pfd.fd = server_sock;
- pfd.events = POLLIN;
-
- int nfds = poll(&pfd, 1, 50);
- if (nfds == 0 || (nfds == -1 && errno == EINTR)) {
- continue;
- }
- if (nfds == -1) {
- perror("poll");
- usleep(100000);
+ // Set back the close-on-exec flag for the socket.
+ // (This can't leak into a child, since we haven't been started yet.)
+ fcntl(server_sock, F_SETFD, FD_CLOEXEC);
+}
+
+AcceptorProto Acceptor::serialize() const
+{
+ // Unset the close-on-exec flag for the socket.
+ // (This can't leak into a child, since there's only one thread left.)
+ fcntl(server_sock, F_SETFD, 0);
+
+ char buf[INET6_ADDRSTRLEN];
+ inet_ntop(addr.sin6_family, &addr.sin6_addr, buf, sizeof(buf));
+
+ AcceptorProto serialized;
+ serialized.set_server_sock(server_sock);
+ serialized.set_addr(buf);
+ serialized.set_port(ntohs(addr.sin6_port));
+ serialized.set_certificate_chain(certificate_chain);
+ serialized.set_private_key(private_key);
+ return serialized;
+}
+
+void Acceptor::close_socket()
+{
+ safe_close(server_sock);
+}
+
+void Acceptor::do_work()
+{
+ while (!should_stop()) {
+ if (!wait_for_activity(server_sock, POLLIN, nullptr)) {