diff --git a/src/crystal/system/win32/iocp.cr b/src/crystal/system/win32/iocp.cr index 278c6f564d64..ac218290f789 100644 --- a/src/crystal/system/win32/iocp.cr +++ b/src/crystal/system/win32/iocp.cr @@ -130,25 +130,6 @@ module Crystal::IOCP end end end - - private def try_cancel : Bool - # Microsoft documentation: - # The application must not free or reuse the OVERLAPPED structure - # associated with the canceled I/O operations until they have completed - # (this does not apply to asynchronous operations that finished - # synchronously, as nothing would be queued to the IOCP) - ret = LibC.CancelIoEx(@handle, self) - if ret.zero? - case error = WinError.value - when .error_not_found? - # Operation has already completed, do nothing - return false - else - raise RuntimeError.from_os_error("CancelIoEx", os_error: error) - end - end - true - end end class IOOverlappedOperation < OverlappedOperation @@ -168,6 +149,25 @@ module Crystal::IOCP bytes end + + private def try_cancel : Bool + # Microsoft documentation: + # The application must not free or reuse the OVERLAPPED structure + # associated with the canceled I/O operations until they have completed + # (this does not apply to asynchronous operations that finished + # synchronously, as nothing would be queued to the IOCP) + ret = LibC.CancelIoEx(@handle, self) + if ret.zero? + case error = WinError.value + when .error_not_found? + # Operation has already completed, do nothing + return false + else + raise RuntimeError.from_os_error("CancelIoEx", os_error: error) + end + end + true + end end class WSAOverlappedOperation < OverlappedOperation @@ -188,6 +188,25 @@ module Crystal::IOCP bytes end + + private def try_cancel : Bool + # Microsoft documentation: + # The application must not free or reuse the OVERLAPPED structure + # associated with the canceled I/O operations until they have completed + # (this does not apply to asynchronous operations that finished + # synchronously, as nothing would be queued to the IOCP) + ret = LibC.CancelIoEx(Pointer(Void).new(@handle), self) + if ret.zero? + case error = WinError.value + when .error_not_found? + # Operation has already completed, do nothing + return false + else + raise RuntimeError.from_os_error("CancelIoEx", os_error: error) + end + end + true + end end def self.overlapped_operation(file_descriptor, method, timeout, *, offset = nil, writing = false, &)