Skip to content

Commit

Permalink
fix compilation
Browse files Browse the repository at this point in the history
On Linux, there are no optional methods in protocols
  • Loading branch information
mickeyl committed May 11, 2021
1 parent 8340cbc commit 2ee18e7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import PackageDescription
let package = Package(
name: "CornucopiaStreams",
platforms: [
.macOS(.v10_13),
.iOS(.v10),
.tvOS(.v10),
.watchOS(.v3),
.macOS("10.15.4"),
.iOS("13.4"),
.tvOS("13.4"),
.watchOS("6"),
],
products: [
.library(
Expand Down
2 changes: 1 addition & 1 deletion Sources/CornucopiaStreams/BLE/AccessoryManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ extension BLEAccessoryManager: CBPeripheralDelegate {
self.activeSessions[peripheral.identifier] = streamProvider

guard let handler = self.pendingConnections.removeValue(forKey: service.uuid) else {
os_log("Did discover characteristics for service %@, but there is no pending connection for this UUID anymore.", service.uuid.description)
os_log("Did discover characteristics for service %@, but there is no pending connection for this UUID anymore.", log: log, type: .info, service.uuid.description)
return
}
let result = FindServiceResult.success(streamProvider)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,31 @@ class FileHandleInputStream: InputStream {
guard self._streamStatus != .open else { return }

_ = NotificationCenter.default.addObserver(forName: Notification.Name.NSFileHandleDataAvailable, object: self.fileHandle, queue: nil) { notification in
self.delegate?.stream(self, handle: .hasBytesAvailable)
#if os(Linux)
self._delegate?.stream(self, handle: .hasBytesAvailable)
#else
self._delegate?.stream?(self, handle: .hasBytesAvailable)
#endif
}
self.fileHandle.waitForDataInBackgroundAndNotify()
self._streamStatus = .open
#if os(Linux)
self.delegate?.stream(self, handle: .openCompleted)
#else
self.delegate?.stream?(self, handle: .openCompleted)
#endif
}

override var hasBytesAvailable: Bool { true }

override func read(_ buffer: UnsafeMutablePointer<UInt8>, maxLength len: Int) -> Int {
guard _streamStatus == .open else { return 0 }
guard let data = try? self.fileHandle.read(upToCount: 1) else {
self.delegate?.stream(self, handle: .endEncountered)
#if os(Linux)
self._delegate?.stream(self, handle: .endEncountered)
#else
self._delegate?.stream?(self, handle: .endEncountered)
#endif
return 0
}
if data.count > 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ class FileHandleOutputStream: OutputStream {
override func open() {
guard self._streamStatus != .open else { return }
self._streamStatus = .open
self.delegate?.stream(self, handle: .openCompleted)
#if os(Linux)
_delegate?.stream(self, handle: .openCompleted)
#else
_delegate?.stream?(self, handle: .openCompleted)
#endif
}

override var hasSpaceAvailable: Bool { true }
Expand Down

0 comments on commit 2ee18e7

Please sign in to comment.