Avoid hang in vepalib::ws::Acceptor::accept_main on systems where
shutdown on socket doesn't wake up a blocking accept call on same socket.
#include "acceptor.h"
#include <vespa/vespalib/net/socket_spec.h>
#include <functional>
+#ifdef __APPLE__
+#include <poll.h>
+#endif
namespace vespalib::ws {
void
Acceptor::accept_main(Handler<Socket> &socket_handler)
{
+#ifdef __APPLE__
+ _server_socket.set_blocking(false);
+#endif
while (!_is_closed) {
+#ifdef __APPLE__
+ pollfd fds;
+ fds.fd = _server_socket.get_fd();
+ fds.events = POLLIN;
+ fds.revents = 0;
+ int res = poll(&fds, 1, 10);
+ if (res < 1 || fds.revents == 0 || _is_closed) {
+ continue;
+ }
+#endif
SocketHandle handle = _server_socket.accept();
if (handle.valid()) {
+#ifdef __APPLE__
+ handle.set_blocking(true);
+#endif
socket_handler.handle(std::make_unique<SimpleSocket>(std::move(handle)));
}
}
