mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
Another Linux fix.
This commit is contained in:
parent
e8c6b4ab16
commit
954f6a77e5
2 changed files with 14 additions and 2 deletions
|
@ -92,7 +92,8 @@ LinuxEthernetTap::LinuxEthernetTap(
|
||||||
_homePath(homePath),
|
_homePath(homePath),
|
||||||
_mtu(mtu),
|
_mtu(mtu),
|
||||||
_fd(0),
|
_fd(0),
|
||||||
_enabled(true)
|
_enabled(true),
|
||||||
|
_run(true)
|
||||||
{
|
{
|
||||||
static std::mutex s_tapCreateLock;
|
static std::mutex s_tapCreateLock;
|
||||||
char procpath[128],nwids[32];
|
char procpath[128],nwids[32];
|
||||||
|
@ -184,6 +185,7 @@ LinuxEthernetTap::LinuxEthernetTap(
|
||||||
|
|
||||||
(void)::pipe(_shutdownSignalPipe);
|
(void)::pipe(_shutdownSignalPipe);
|
||||||
|
|
||||||
|
_thread_init_l.lock();
|
||||||
for(unsigned int t=0;t<2;++t) {
|
for(unsigned int t=0;t<2;++t) {
|
||||||
_tapReaderThread[t] = std::thread([this, t]{
|
_tapReaderThread[t] = std::thread([this, t]{
|
||||||
fd_set readfds,nullfds;
|
fd_set readfds,nullfds;
|
||||||
|
@ -236,10 +238,16 @@ LinuxEthernetTap::LinuxEthernetTap(
|
||||||
fcntl(_fd,F_SETFL,O_NONBLOCK);
|
fcntl(_fd,F_SETFL,O_NONBLOCK);
|
||||||
|
|
||||||
::close(sock);
|
::close(sock);
|
||||||
|
|
||||||
|
_thread.init_l.unlock();
|
||||||
} else {
|
} else {
|
||||||
usleep(1500000);
|
_thread_init_l.lock();
|
||||||
|
_thread_init_l.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_run)
|
||||||
|
return;
|
||||||
|
|
||||||
FD_ZERO(&readfds);
|
FD_ZERO(&readfds);
|
||||||
FD_ZERO(&nullfds);
|
FD_ZERO(&nullfds);
|
||||||
nfds = (int)std::max(_shutdownSignalPipe[0],_fd) + 1;
|
nfds = (int)std::max(_shutdownSignalPipe[0],_fd) + 1;
|
||||||
|
@ -324,6 +332,8 @@ LinuxEthernetTap::LinuxEthernetTap(
|
||||||
|
|
||||||
LinuxEthernetTap::~LinuxEthernetTap()
|
LinuxEthernetTap::~LinuxEthernetTap()
|
||||||
{
|
{
|
||||||
|
_run = false;
|
||||||
|
|
||||||
(void)::write(_shutdownSignalPipe[1],"\0",1); // causes reader thread(s) to exit
|
(void)::write(_shutdownSignalPipe[1],"\0",1); // causes reader thread(s) to exit
|
||||||
_tapq.post(std::pair<void *,int>(nullptr,0)); // causes processor thread to exit
|
_tapq.post(std::pair<void *,int>(nullptr,0)); // causes processor thread to exit
|
||||||
|
|
||||||
|
|
|
@ -70,9 +70,11 @@ private:
|
||||||
int _fd;
|
int _fd;
|
||||||
int _shutdownSignalPipe[2];
|
int _shutdownSignalPipe[2];
|
||||||
std::atomic_bool _enabled;
|
std::atomic_bool _enabled;
|
||||||
|
std::atomic_bool _run;
|
||||||
std::thread _tapReaderThread[2];
|
std::thread _tapReaderThread[2];
|
||||||
std::thread _tapProcessorThread;
|
std::thread _tapProcessorThread;
|
||||||
std::mutex _buffers_l;
|
std::mutex _buffers_l;
|
||||||
|
std::mutex _thread_init_l;
|
||||||
std::vector<void *> _buffers;
|
std::vector<void *> _buffers;
|
||||||
BlockingQueue< std::pair<void *,int> > _tapq;
|
BlockingQueue< std::pair<void *,int> > _tapq;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue