[tor-commits] [tor/master] Make example CancelIoEx() code use CancelIo().

nickm at torproject.org nickm at torproject.org
Thu Dec 20 16:44:56 UTC 2018


commit 412fbe9f177f742e0e56df612f44261f6771973a
Author: Alexander Færøy <ahf at torproject.org>
Date:   Thu Dec 20 13:11:24 2018 +0100

    Make example CancelIoEx() code use CancelIo().
    
    This patch changes the CancelIoEx() example code to use CancelIo(),
    which is available for older versions of Windows too. I still think the
    kernel handles this nicely by sending broken pipes if either side
    closes the pipe while I/O operations are pending.
    
    See: https://bugs.torproject.org/28179
---
 src/lib/process/process_win32.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/src/lib/process/process_win32.c b/src/lib/process/process_win32.c
index 3b4373f42..641af2bb0 100644
--- a/src/lib/process/process_win32.c
+++ b/src/lib/process/process_win32.c
@@ -720,31 +720,24 @@ process_win32_cleanup_handle(process_win32_handle_t *handle)
   tor_assert(handle);
 
 #if 0
-  /* FIXME(ahf): My compiler does not set _WIN32_WINNT to a high enough value
-   * for this code to be available. Should we force it? CancelIoEx() is
-   * available from Windows 7 and above. If we decide to require this, we need
-   * to update the checks in all the three I/O completion callbacks to handle
-   * the ERROR_OPERATION_ABORTED as well as ERROR_BROKEN_PIPE. */
-
-#if _WIN32_WINNT >= 0x0600
-  /* This code is only supported from Windows 7 and onwards. */
   BOOL ret;
   DWORD error_code;
 
-  /* Cancel any pending I/O requests. */
-  ret = CancelIoEx(handle->pipe, &handle->overlapped);
+  /* Cancel any pending I/O requests: This means that instead of getting
+   * ERROR_BROKEN_PIPE we get ERROR_OPERATION_ABORTED, but it doesn't seem
+   * like this is needed. */
+  ret = CancelIo(handle->pipe);
 
   if (! ret) {
     error_code = GetLastError();
 
     /* There was no pending I/O requests for our handle. */
     if (error_code != ERROR_NOT_FOUND) {
-      log_warn(LD_PROCESS, "CancelIoEx() failed: %s",
+      log_warn(LD_PROCESS, "CancelIo() failed: %s",
                format_win32_error(error_code));
     }
   }
 #endif
-#endif
 
   /* Close our handle. */
   if (handle->pipe != INVALID_HANDLE_VALUE) {





More information about the tor-commits mailing list