Skip to content

Commit

Permalink
修复未设置 MacOS Tun 非阻塞导致的进程退出异常
Browse files Browse the repository at this point in the history
  • Loading branch information
lanthora committed Dec 19, 2023
1 parent e524bab commit eb6fabe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 10 additions & 0 deletions src/tun/darwin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit eb6fabe

Please sign in to comment.