mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-18 10:46:33 +00:00
Another Linux fix.
This commit is contained in:
parent
e8c6b4ab16
commit
954f6a77e5
@ -92,7 +92,8 @@ LinuxEthernetTap::LinuxEthernetTap(
|
||||
_homePath(homePath),
|
||||
_mtu(mtu),
|
||||
_fd(0),
|
||||
_enabled(true)
|
||||
_enabled(true),
|
||||
_run(true)
|
||||
{
|
||||
static std::mutex s_tapCreateLock;
|
||||
char procpath[128],nwids[32];
|
||||
@ -184,6 +185,7 @@ LinuxEthernetTap::LinuxEthernetTap(
|
||||
|
||||
(void)::pipe(_shutdownSignalPipe);
|
||||
|
||||
_thread_init_l.lock();
|
||||
for(unsigned int t=0;t<2;++t) {
|
||||
_tapReaderThread[t] = std::thread([this, t]{
|
||||
fd_set readfds,nullfds;
|
||||
@ -236,10 +238,16 @@ LinuxEthernetTap::LinuxEthernetTap(
|
||||
fcntl(_fd,F_SETFL,O_NONBLOCK);
|
||||
|
||||
::close(sock);
|
||||
|
||||
_thread.init_l.unlock();
|
||||
} else {
|
||||
usleep(1500000);
|
||||
_thread_init_l.lock();
|
||||
_thread_init_l.unlock();
|
||||
}
|
||||
|
||||
if (!_run)
|
||||
return;
|
||||
|
||||
FD_ZERO(&readfds);
|
||||
FD_ZERO(&nullfds);
|
||||
nfds = (int)std::max(_shutdownSignalPipe[0],_fd) + 1;
|
||||
@ -324,6 +332,8 @@ LinuxEthernetTap::LinuxEthernetTap(
|
||||
|
||||
LinuxEthernetTap::~LinuxEthernetTap()
|
||||
{
|
||||
_run = false;
|
||||
|
||||
(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
|
||||
|
||||
|
@ -70,9 +70,11 @@ private:
|
||||
int _fd;
|
||||
int _shutdownSignalPipe[2];
|
||||
std::atomic_bool _enabled;
|
||||
std::atomic_bool _run;
|
||||
std::thread _tapReaderThread[2];
|
||||
std::thread _tapProcessorThread;
|
||||
std::mutex _buffers_l;
|
||||
std::mutex _thread_init_l;
|
||||
std::vector<void *> _buffers;
|
||||
BlockingQueue< std::pair<void *,int> > _tapq;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user