From eb6fabe8c01b3193e88eba5401bd53ff1b5a6bc6 Mon Sep 17 00:00:00 2001 From: lanthora Date: Tue, 19 Dec 2023 17:43:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9C=AA=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=20MacOS=20Tun=20=E9=9D=9E=E9=98=BB=E5=A1=9E=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84=E8=BF=9B=E7=A8=8B=E9=80=80=E5=87=BA=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/posix.cc | 2 +- src/tun/darwin.cc | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/posix.cc b/src/main/posix.cc index c40d7d04..a58a3bd2 100644 --- a/src/main/posix.cc +++ b/src/main/posix.cc @@ -152,7 +152,7 @@ struct argp config = { }; volatile int exitCode = 0; -bool running = true; +volatile bool running = true; std::mutex mutex; std::condition_variable condition; diff --git a/src/tun/darwin.cc b/src/tun/darwin.cc index 0478cfec..007164c2 100644 --- a/src/tun/darwin.cc +++ b/src/tun/darwin.cc @@ -58,6 +58,16 @@ class DarwinTun { spdlog::critical("create socket failed: {}", strerror(errno)); return -1; } + int flags = fcntl(this->tunFd, F_GETFL, 0); + if (flags < 0) { + spdlog::error("get tun flags failed: {}", strerror(errno)); + return -1; + } + flags |= O_NONBLOCK; + if (fcntl(this->tunFd, F_SETFL, flags) < 0) { + spdlog::error("set non-blocking tun failed: {}", strerror(errno)); + return -1; + } struct ctl_info info; memset(&info, 0, sizeof(info));