|
12 | 12 |
|
13 | 13 | import CDispatch
|
14 | 14 | import _SwiftDispatchOverlayShims
|
| 15 | +#if os(Windows) |
| 16 | +import WinSDK |
| 17 | +#endif |
15 | 18 |
|
16 | 19 | extension DispatchSourceProtocol {
|
17 | 20 |
|
@@ -179,7 +182,13 @@ extension DispatchSource {
|
179 | 182 | #endif
|
180 | 183 |
|
181 | 184 | public class func makeReadSource(fileDescriptor: Int32, queue: DispatchQueue? = nil) -> DispatchSourceRead {
|
182 |
| - let source = dispatch_source_create(_swift_dispatch_source_type_READ(), UInt(fileDescriptor), 0, queue?.__wrapped) |
| 185 | +#if os(Windows) |
| 186 | + let handle: UInt = UInt(_get_osfhandle(fileDescriptor)) |
| 187 | + if handle == UInt(bitPattern: INVALID_HANDLE_VALUE) { fatalError("unable to get underlying handle from file descriptor") } |
| 188 | +#else |
| 189 | + let handle: UInt = UInt(fileDescriptor) |
| 190 | +#endif |
| 191 | + let source = dispatch_source_create(_swift_dispatch_source_type_READ(), handle, 0, queue?.__wrapped) |
183 | 192 | return DispatchSource(source: source) as DispatchSourceRead
|
184 | 193 | }
|
185 | 194 |
|
@@ -216,7 +225,13 @@ extension DispatchSource {
|
216 | 225 | #endif
|
217 | 226 |
|
218 | 227 | public class func makeWriteSource(fileDescriptor: Int32, queue: DispatchQueue? = nil) -> DispatchSourceWrite {
|
219 |
| - let source = dispatch_source_create(_swift_dispatch_source_type_WRITE(), UInt(fileDescriptor), 0, queue?.__wrapped) |
| 228 | +#if os(Windows) |
| 229 | + let handle: UInt = UInt(_get_osfhandle(fileDescriptor)) |
| 230 | + if handle == UInt(bitPattern: INVALID_HANDLE_VALUE) { fatalError("unable to get underlying handle from file descriptor") } |
| 231 | +#else |
| 232 | + let handle: UInt = UInt(fileDescriptor) |
| 233 | +#endif |
| 234 | + let source = dispatch_source_create(_swift_dispatch_source_type_WRITE(), handle, 0, queue?.__wrapped) |
220 | 235 | return DispatchSource(source: source) as DispatchSourceWrite
|
221 | 236 | }
|
222 | 237 | }
|
|
0 commit comments