From 0d4e27489e1a6ad4df33ac9df3dae9c694d8048f Mon Sep 17 00:00:00 2001 From: "T.Sasaki" Date: Mon, 10 Dec 2018 14:48:59 +0900 Subject: [PATCH] Fixed bug: cannot be transferred file 4KB or less --- Sources/FPSStreamTask.swift | 20 ++++++++++++++------ Sources/FTPHelper.swift | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Sources/FPSStreamTask.swift b/Sources/FPSStreamTask.swift index 76959b4..bfe0a2d 100644 --- a/Sources/FPSStreamTask.swift +++ b/Sources/FPSStreamTask.swift @@ -542,9 +542,6 @@ public class FileProviderStreamTask: URLSessionTask, StreamDelegate { } return } - if data.count > 4096 { - isUploadTask = true - } self.dataToBeSentLock.lock() self.dataToBeSent.append(data) @@ -611,8 +608,6 @@ public class FileProviderStreamTask: URLSessionTask, StreamDelegate { fileprivate var shouldCloseWrite = false - fileprivate var isUploadTask = false - /** * Completes any enqueued reads and writes, and then closes the read side of the underlying socket. * @@ -621,6 +616,19 @@ public class FileProviderStreamTask: URLSessionTask, StreamDelegate { * after calling this method will result in an error. */ open func closeRead() { + closeRead(immediate: false) + } + + /** + * Completes any enqueued reads and writes, and then closes the read side of the underlying socket. + * + * You may continue to write data using the `write(_:timeout:completionHandler:)` method after + * calling this method. Any calls to `readData(ofMinLength:maxLength:timeout:completionHandler:)` + * after calling this method will result in an error. + * + * - Parameter immediate: close immediatly if true. + */ + open func closeRead(immediate: Bool) { if #available(iOS 9.0, macOS 10.11, *) { if self.useURLSession { _underlyingTask!.closeRead() @@ -632,7 +640,7 @@ public class FileProviderStreamTask: URLSessionTask, StreamDelegate { return } dispatch_queue.async { - if !self.isUploadTask { + if !immediate { while inputStream.streamStatus != .atEnd { Thread.sleep(forTimeInterval: 0.1) } diff --git a/Sources/FTPHelper.swift b/Sources/FTPHelper.swift index c11bac6..7fc7925 100644 --- a/Sources/FTPHelper.swift +++ b/Sources/FTPHelper.swift @@ -804,7 +804,7 @@ internal extension FTPFileProvider { dataTask.stopSecureConnection() } // TOFIX: Close read/write stream for receive a FTP response from the server - dataTask.closeRead() + dataTask.closeRead(immediate: true) dataTask.closeWrite() }) { (response, error) in do {