Skip to content

Commit

Permalink
Fixed LocalFileMonitor dir not refreshing, Fixed FTP connection refus…
Browse files Browse the repository at this point in the history
…ed error by retrying
  • Loading branch information
amosavian committed Apr 25, 2018
1 parent 4202f5e commit f2cd571
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
21 changes: 19 additions & 2 deletions Sources/FPSStreamTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -790,10 +790,27 @@ public class FileProviderStreamTask: URLSessionTask, StreamDelegate {
}
}

private var _retriesForInputStream: Int = 0
private var _retriesForOutputStream: Int = 0
open func stream(_ aStream: Stream, handle eventCode: Stream.Event) {
if eventCode.contains(.errorOccurred) {
self._error = aStream.streamError
streamDelegate?.urlSession?(_underlyingSession, task: self, didCompleteWithError: error)
let retries: Int
if aStream == self.inputStream {
retries = _retriesForInputStream
_retriesForInputStream += 1
} else if aStream == self.outputStream {
retries = _retriesForOutputStream
_retriesForOutputStream += 1
} else {
return
}

if retries < 3 {
aStream.open()
} else {
self._error = aStream.streamError
streamDelegate?.urlSession?(_underlyingSession, task: self, didCompleteWithError: error)
}
}

if aStream == self.inputStream && eventCode.contains(.hasBytesAvailable) {
Expand Down
4 changes: 3 additions & 1 deletion Sources/LocalHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public final class LocalFileMonitor {
public init(url: URL, handler: @escaping ()->Void) {
self.url = url
descriptor = open((url.absoluteURL as NSURL).fileSystemRepresentation, O_EVTONLY)
source = DispatchSource.makeFileSystemObjectSource(fileDescriptor: descriptor, eventMask: [.write, .extend, .attrib, .delete, .rename], queue: qq)
let event: DispatchSource.FileSystemEvent = url.fileIsDirectory ? [.write] : .all
source = DispatchSource.makeFileSystemObjectSource(fileDescriptor: descriptor, eventMask: event, queue: qq)

// Folder monitoring is recursive and deep. Monitoring a root folder may be very costly
// We have a 0.2 second delay to ensure we wont call handler 1000s times when there is
// a huge file operation. This ensures app will work smoothly while this 250 milisec won't
Expand Down

0 comments on commit f2cd571

Please sign in to comment.