@@ -28,4 +28,5 @@ libcompat_la_SOURCES = \
compat-gettimeofday.c \
compat-daemon.c \
compat-strsep.c \
- compat-versionhelpers.h
+ compat-versionhelpers.h \
+ compat-dco_get_overlapped_result.c
new file mode 100644
@@ -0,0 +1,44 @@
+/*
+ * OpenVPN -- An application to securely tunnel IP networks
+ * over a single UDP port, with support for SSL/TLS-based
+ * session authentication and key exchange,
+ * packet encryption, packet authentication, and
+ * packet compression.
+ *
+ * Copyright (C) 2021 Lev Stipakov <lev@openvpn.net>
+ * Copyright (C) 2021 OpenVPN Inc <sales@openvpn.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING included with this
+ * distribution); if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#elif defined(_MSC_VER)
+#include "config-msvc.h"
+#endif
+
+#include "compat.h"
+
+#if defined(__MINGW32__) && !defined(__MINGW64__)
+BOOL dco_get_overlapped_result(HANDLE handle, OVERLAPPED* ov, DWORD* transferred, DWORD delay_millisec, BOOL unused)
+{
+ BOOL res = GetOverlappedResult(handle, ov, transferred, FALSE);
+ if ((res == 0) && (GetLastError() == ERROR_IO_INCOMPLETE))
+ {
+ Sleep(delay_millisec);
+ }
+ return res;
+}
+#endif
@@ -62,4 +62,10 @@ char *strsep(char **stringp, const char *delim);
#endif
+#if defined(__MINGW32__) && !defined(__MINGW64__)
+BOOL dco_get_overlapped_result(HANDLE handle, OVERLAPPED* ov, DWORD* transferred, DWORD delay_millisec, BOOL unused);
+#else
+#define dco_get_overlapped_result GetOverlappedResultEx
+#endif
+
#endif /* COMPAT_H */
@@ -159,6 +159,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="compat-basename.c" />
+ <ClCompile Include="compat-dco_get_overlapped_result.c" />
<ClCompile Include="compat-dirname.c" />
<ClCompile Include="compat-gettimeofday.c" />
<ClCompile Include="compat-daemon.c" />
@@ -30,6 +30,9 @@
<ClCompile Include="compat-strsep.c">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="compat-dco_get_overlapped_result.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="compat.h">
@@ -74,17 +74,22 @@ void dco_start_tun(struct tuntap* tt)
int dco_connect_wait(HANDLE handle, OVERLAPPED* ov, int timeout, volatile int* signal_received)
{
- while (timeout-- > 0)
+ DWORD timeout_msec = timeout * 1000;
+ const int poll_interval_ms = 50;
+
+ while (timeout_msec > 0)
{
+ timeout_msec -= poll_interval_ms;
+
DWORD transferred;
- if (GetOverlappedResultEx(handle, ov, &transferred, 1000, FALSE) != 0)
+ if (dco_get_overlapped_result(handle, ov, &transferred, poll_interval_ms, FALSE) != 0)
{
/* TCP connection established by dco */
return 0;
}
DWORD err = GetLastError();
- if (err != WAIT_TIMEOUT)
+ if ((err != WAIT_TIMEOUT) && (err != ERROR_IO_INCOMPLETE))
{
/* dco reported connection error */
struct gc_arena gc = gc_new();