face: support IPv6-only WebSocket channels
Change-Id: Ib9ba27d04611c13882e50995d701fc1b707cea5f
Refs: #4710
diff --git a/daemon/face/websocket-channel.cpp b/daemon/face/websocket-channel.cpp
index ca149b3..c4c392b 100644
--- a/daemon/face/websocket-channel.cpp
+++ b/daemon/face/websocket-channel.cpp
@@ -46,6 +46,12 @@
// Setup WebSocket server
m_server.init_asio(&getGlobalIoService());
+ m_server.set_tcp_pre_bind_handler([isV6 = m_localEndpoint.address().is_v6()] (const auto& acceptor) {
+ if (isV6) {
+ acceptor->set_option(boost::asio::ip::v6_only(true));
+ }
+ return websocketpp::lib::error_code{};
+ });
m_server.set_open_handler(bind(&WebSocketChannel::handleOpen, this, _1));
m_server.set_close_handler(bind(&WebSocketChannel::handleClose, this, _1));
m_server.set_message_handler(bind(&WebSocketChannel::handleMessage, this, _1, _2));