diff options
author | Adam Ierymenko <adam.ierymenko@zerotier.com> | 2014-03-27 18:50:10 -0700 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@zerotier.com> | 2014-03-27 18:50:10 -0700 |
commit | 881ff08269cae26534a04566cffe4dc2a873ca88 (patch) | |
tree | a0103635500113d93655361da50a393949f65eae /node | |
parent | e3239d23f4b8e293dae46b98bfd7ac45bb3d5185 (diff) | |
download | infinitytier-881ff08269cae26534a04566cffe4dc2a873ca88.tar.gz infinitytier-881ff08269cae26534a04566cffe4dc2a873ca88.zip |
Make multiple attempts to open the tap device on Windows.
Diffstat (limited to 'node')
-rw-r--r-- | node/EthernetTap.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/node/EthernetTap.cpp b/node/EthernetTap.cpp index 61e9fbca..5b7ea575 100644 --- a/node/EthernetTap.cpp +++ b/node/EthernetTap.cpp @@ -1287,6 +1287,7 @@ EthernetTap::EthernetTap( CloseHandle(processInfo.hProcess); CloseHandle(processInfo.hThread); } + Sleep(250); { STARTUPINFOA startupInfo; startupInfo.cb = sizeof(startupInfo); @@ -1309,14 +1310,22 @@ EthernetTap::EthernetTap( } if (devconLog != INVALID_HANDLE_VALUE) CloseHandle(devconLog); + Sleep(250); } // Open the tap, which is in this weird Windows analog of /dev char tapPath[4096]; Utils::snprintf(tapPath,sizeof(tapPath),"\\\\.\\Global\\%s.tap",_myDeviceInstanceId.c_str()); - _tap = CreateFileA(tapPath,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_SYSTEM|FILE_FLAG_OVERLAPPED,NULL); - if (_tap == INVALID_HANDLE_VALUE) - throw std::runtime_error(std::string("unable to open tap device ")+tapPath); + for(int openTrials=0;;) { + // Try multiple times, since there seem to be reports from the field + // of driver init timing issues. Blech. + _tap = CreateFileA(tapPath,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_SYSTEM|FILE_FLAG_OVERLAPPED,NULL); + if (_tap == INVALID_HANDLE_VALUE) { + if (++openTrials >= 3) + throw std::runtime_error(std::string("unable to open tap device ")+tapPath); + else Sleep(500); + } else break; + } // Set media status to enabled uint32_t tmpi = 1; |