Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Sep 7, 2024
1 parent c092dbc commit 6f896ad
Showing 1 changed file with 38 additions and 19 deletions.
57 changes: 38 additions & 19 deletions src/crystal/system/win32/iocp.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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, &)
Expand Down

0 comments on commit 6f896ad

Please sign in to comment.