Skip to content

Commit

Permalink
Merge pull request #139 from sasaki-945/master
Browse files Browse the repository at this point in the history
Fixed bug: cannot be transferred file 4KB or less
  • Loading branch information
amosavian committed Dec 16, 2018
2 parents cb42552 + 90706f1 commit 9384264
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions Sources/FPSStreamTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,6 @@ public class FileProviderStreamTask: URLSessionTask, StreamDelegate {
}
return
}
if data.count > 4096 {
isUploadTask = true
}

self.dataToBeSentLock.lock()
self.dataToBeSent.append(data)
Expand Down Expand Up @@ -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.
*
Expand All @@ -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()
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/FTPHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9384264

Please sign in to comment.