Skip to content

HACK: make FileHandle build on Windows again #1955

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions Foundation/FileHandle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,6 @@ open class FileHandle : NSObject, NSSecureCoding {
return source
}

#if os(Windows)
@available(*, unavailable, message: "Not yet implemented on Windows")
open var readabilityHandler: ((FileHandle) -> Void)? = {
(FileHandle) -> Void in NSUnimplemented()
}

@available(*, unavailable, message: "Not yet implemented on Windows")
open var writeabilityHandler: ((FileHandle) -> Void)? = {
(FileHandle) -> Void in NSUnimplemented()
}
#else
private var _readabilityHandler: ((FileHandle) -> Void)? = nil // Guarded by privateAsyncVariablesLock
open var readabilityHandler: ((FileHandle) -> Void)? {
get {
Expand Down Expand Up @@ -200,7 +189,6 @@ open class FileHandle : NSObject, NSSecureCoding {
}
}
}
#endif

open var availableData: Data {
_checkFileHandle()
Expand Down Expand Up @@ -891,7 +879,11 @@ extension FileHandle {
acceptConnectionInBackgroundAndNotify(forModes: [.default])
}

@available(Windows, unavailable, message: "A SOCKET cannot be treated as a fd")
open func acceptConnectionInBackgroundAndNotify(forModes modes: [RunLoop.Mode]?) {
#if os(Windows)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is for treating fds like sockets, it's fine if this is unavailable on Windows only.

NSUnavailable()
#else
let owner = monitor(forReading: true, resumed: false) { (handle, source) in
var notification = Notification(name: .NSFileHandleConnectionAccepted, object: handle, userInfo: [:])
let userInfo: [AnyHashable : Any]
Expand Down Expand Up @@ -919,6 +911,7 @@ extension FileHandle {
privateAsyncVariablesLock.unlock()

owner.resume()
#endif
}

open func waitForDataInBackgroundAndNotify() {
Expand Down