-
Notifications
You must be signed in to change notification settings - Fork 26
Introduce IOCP based AsyncIO for Windows #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iCharlesHu
wants to merge
7
commits into
swiftlang:main
Choose a base branch
from
iCharlesHu:charles/windows-async-io
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,614
−620
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b6181ea
Create platform specific AsyncIO
iCharlesHu e374669
Refactor captureOutput() to minimize force unwrap
iCharlesHu 61508ad
Create platform specific AsyncIO
iCharlesHu a72d35f
Fix fd was not closed error on Windows
iCharlesHu 74995e4
Fix Windows test errors
iCharlesHu 44a9e97
Introduce Windows IOCP based AsyncIO implementation
iCharlesHu 22e4b38
Move platform specific AsyncIO implementations to separate files
iCharlesHu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,18 +17,8 @@ | |
extension AsyncBufferSequence { | ||
/// A immutable collection of bytes | ||
public struct Buffer: Sendable { | ||
#if os(Windows) | ||
internal let data: [UInt8] | ||
|
||
internal init(data: [UInt8]) { | ||
self.data = data | ||
} | ||
|
||
internal static func createFrom(_ data: [UInt8]) -> [Buffer] { | ||
return [.init(data: data)] | ||
} | ||
#else | ||
// We need to keep the backingData alive while _ContiguousBufferView is alive | ||
#if canImport(Darwin) | ||
// We need to keep the backingData alive while Slice is alive | ||
internal let backingData: DispatchData | ||
internal let data: DispatchData._ContiguousBufferView | ||
|
||
|
@@ -45,7 +35,17 @@ extension AsyncBufferSequence { | |
} | ||
return slices.map{ .init(data: $0, backingData: data) } | ||
} | ||
#endif | ||
#else | ||
internal let data: [UInt8] | ||
|
||
internal init(data: [UInt8]) { | ||
self.data = data | ||
} | ||
|
||
internal static func createFrom(_ data: [UInt8]) -> [Buffer] { | ||
return [.init(data: data)] | ||
} | ||
#endif // canImport(Darwin) | ||
} | ||
} | ||
|
||
|
@@ -92,26 +92,23 @@ extension AsyncBufferSequence.Buffer { | |
|
||
// MARK: - Hashable, Equatable | ||
extension AsyncBufferSequence.Buffer: Equatable, Hashable { | ||
#if os(Windows) | ||
// Compiler generated conformances | ||
#else | ||
#if canImport(Darwin) | ||
public static func == (lhs: AsyncBufferSequence.Buffer, rhs: AsyncBufferSequence.Buffer) -> Bool { | ||
return lhs.data.elementsEqual(rhs.data) | ||
return lhs.data == rhs.data | ||
} | ||
|
||
public func hash(into hasher: inout Hasher) { | ||
self.data.withUnsafeBytes { ptr in | ||
hasher.combine(bytes: ptr) | ||
} | ||
hasher.combine(self.data) | ||
} | ||
#endif | ||
// else Compiler generated conformances | ||
} | ||
|
||
// MARK: - DispatchData.Block | ||
#if canImport(Darwin) || canImport(Glibc) || canImport(Android) || canImport(Musl) | ||
extension DispatchData { | ||
/// Unfortunately `DispatchData.Region` is not available on Linux, hence our own wrapper | ||
internal struct _ContiguousBufferView: @unchecked Sendable, RandomAccessCollection { | ||
internal struct _ContiguousBufferView: @unchecked Sendable, RandomAccessCollection, Hashable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a very dangerous type. If it really has to exist it should be |
||
typealias Element = UInt8 | ||
|
||
internal let bytes: UnsafeBufferPointer<UInt8> | ||
|
@@ -127,6 +124,14 @@ extension DispatchData { | |
return try body(UnsafeRawBufferPointer(self.bytes)) | ||
} | ||
|
||
internal func hash(into hasher: inout Hasher) { | ||
hasher.combine(bytes: UnsafeRawBufferPointer(self.bytes)) | ||
} | ||
|
||
internal static func == (lhs: DispatchData._ContiguousBufferView, rhs: DispatchData._ContiguousBufferView) -> Bool { | ||
return lhs.bytes.elementsEqual(rhs.bytes) | ||
} | ||
|
||
subscript(position: Int) -> UInt8 { | ||
_read { | ||
yield self.bytes[position] | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo