From: Etienne Dechamps Date: Wed, 17 Jan 2018 19:37:53 +0000 (+0000) Subject: Move ResetEvent() call before ReadFile(). X-Git-Tag: release-1.1pre16~32 X-Git-Url: https://tinc-vpn.org/git/browse?a=commitdiff_plain;h=7bf4d225a994d8ce9fb45d42afd53793c4232e8e;p=tinc Move ResetEvent() call before ReadFile(). Commit 313a752 changed the Windows device code such that ResetEvent() is called on the read OVERLAPPED structure before GetOverlappedResult(), as opposed to before ReadFile(). In [1] Guus pointed out that this doesn't make a ton of sense, and I agree with him; it must have been an oversight on my part when I wrote this code. Surprisingly, none of this makes any difference in my testing, at least with the standard TAP 9.0.0.9 driver. Nevertheless, this code is probably wrong and fixing it will make me sleep better at night. [1]: https://www.tinc-vpn.org/pipermail/tinc/2018-January/005091.html --- diff --git a/src/mingw/device.c b/src/mingw/device.c index 49d0cd34..d90c69b0 100644 --- a/src/mingw/device.c +++ b/src/mingw/device.c @@ -54,6 +54,8 @@ static void device_issue_read() { int status; for(;;) { + ResetEvent(device_read_overlapped.hEvent); + DWORD len; status = ReadFile(device_handle, (void *)device_read_packet.data, MTU, &len, &device_read_overlapped); @@ -72,10 +74,7 @@ static void device_issue_read() { } static void device_handle_read(void *data, int flags) { - ResetEvent(device_read_overlapped.hEvent); - DWORD len; - if(!GetOverlappedResult(device_handle, &device_read_overlapped, &len, FALSE)) { logger(DEBUG_ALWAYS, LOG_ERR, "Error getting read result from %s %s: %s", device_info, device, strerror(errno));