Skip to content

Initial implementation of FTP #1122

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

Closed
wants to merge 1 commit into from

Conversation

saiHemak
Copy link
Contributor

@saiHemak saiHemak commented Jul 20, 2017

This PR includes ..

  • FTP Data Task, Download Task implementations ,Upload task with completion handler
  • Refactoring of URLProtocol code to support both FTP and HTTP protocol implementations.
  • Basic FTPServer implementation which supports download,data and upload task
  • Test cases for FTP implementation

@saiHemak saiHemak force-pushed the ftpimplementation branch from 9772656 to 48668a4 Compare July 20, 2017 11:58
@alblue alblue self-requested a review July 20, 2017 18:14
Copy link
Contributor

@alblue alblue left a comment

Choose a reason for hiding this comment

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

Since this is a WIP adding a blocking review to make sure it doesn't get merged at the current stage. Let me know when it's good to go and I can remove this review.

}
}

/* override func transferCompleted(withErrorCode errorCode: Int?) {
Copy link
Member

Choose a reason for hiding this comment

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

We need to remove the commented code.

@@ -128,12 +128,12 @@ internal final class _HTTPBodyFileSource {
guard let channel = DispatchIO(type: .stream, path: fileSystemRepresentation,
oflag: O_RDONLY, mode: 0, queue: workQueue,
cleanupHandler: {_ in }) else {
fatalError("Cant create DispatchIO channel")
fatalError("Cant create DispatchIO channel")
Copy link
Member

Choose a reason for hiding this comment

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

Indentation error.

if let location = response.allHeaderFields[value] as? String {
return location
}
return nil
}
}

Copy link
Member

Choose a reason for hiding this comment

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

These two extra lines could be removed?

@@ -1339,6 +1344,24 @@
path = Foundation;
sourceTree = "<group>";
};
617F57F01F1F5C4B0004F3F0 /* libcurlhelpers */ = {
Copy link
Member

Choose a reason for hiding this comment

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

May be we should call the directory simply libcurl (because it contains libcurl abstractions) instead of libcurlhelpers

internal let enableDebugOutput: Bool = {
return (ProcessInfo.processInfo.environment["URLSessionDebug"] != nil)
}()

Copy link
Member

@pushkarnk pushkarnk Jul 21, 2017

Choose a reason for hiding this comment

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

It may help if we could add a line or two describing the role of this new internal class :-)

return .completeTask
}

func seekInputStream(to position: UInt64) throws {
Copy link
Member

Choose a reason for hiding this comment

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

Empty method?

@@ -0,0 +1,700 @@
// Foundation/NSURLSession/TransferState.swift - NSURLSession & libcurl
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this header refer to an apparently non-existent other file?

// Foundation
//
// Created by sai hema on 6/27/17.
// Copyright © 2017 Apple. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be replaced with the standard header found in other Foundation files.

task?.response = response
//We don't want a timeout to be triggered after this. The timeout timer needs to be cancelled.
easyHandle.timeoutTimer = nil
//because we deregister the task with the session on internalState being set to taskCompleted
Copy link
Contributor

Choose a reason for hiding this comment

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

Please rewrap, capitalize, and space these comments to match the rest of the file.

@saiHemak saiHemak force-pushed the ftpimplementation branch 2 times, most recently from 705dc5b to 39e96d8 Compare July 26, 2017 08:50
@pushkarnk
Copy link
Member

@saiHemak Does the refactored code consider #1121 and #1132 ? Thanks.

@saiHemak saiHemak force-pushed the ftpimplementation branch from 39e96d8 to 9fa771e Compare July 28, 2017 06:44
@saiHemak saiHemak force-pushed the ftpimplementation branch 4 times, most recently from ccc22de to e8fdce9 Compare September 4, 2017 09:04
@saiHemak saiHemak force-pushed the ftpimplementation branch 4 times, most recently from de89c00 to da13e79 Compare September 11, 2017 08:13
@ianpartridge
Copy link
Contributor

@swift-ci please test

@saiHemak
Copy link
Contributor Author

@pushkarnk Yes ..I have taken care of it ..

Copy link
Contributor

@ianpartridge ianpartridge left a comment

Choose a reason for hiding this comment

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

I've made a few basic review comments but had to stop as the PR is so large it is extremely difficult to review.

I would much prefer it if this was broken down into a series of incremental commits.

@@ -47,7 +47,7 @@ open class URLSessionConfiguration : NSObject, NSCopying {
self.urlCredentialStorage = nil
self.urlCache = nil
self.shouldUseExtendedBackgroundIdleMode = false
self.protocolClasses = [_HTTPURLProtocol.self]
self.protocolClasses = [_HTTPURLProtocol.self,_FTPURLProtocol.self]
Copy link
Contributor

Choose a reason for hiding this comment

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

Space after comma.

@@ -0,0 +1,155 @@
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

/// return value's `isHeaderComplete` will then by `true`.
///
/// - Throws: When a parsing error occurs
func byAppendingFTP(headerLine data: Data, exectedContentLength: Int64) throws -> _NativeProtocol._TransferState {
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: expectedContentLength

@@ -40,15 +40,15 @@ internal func splitData(dispatchData data: DispatchData, atPosition position: In
}

/// A (non-blocking) source for HTTP body data.
internal protocol _HTTPBodySource: class {
internal protocol _BodySource: class {
Copy link
Contributor

Choose a reason for hiding this comment

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

As this is no longer specific to HTTP, should it be moved out of the http directory?

}

override func configureEasyHandle(for request: URLRequest) {
//easyHandle.set(verboseModeOn: true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove these comments.

@saiHemak
Copy link
Contributor Author

@ianpartridge , I have addressed your comments.

@saiHemak
Copy link
Contributor Author

@ianpartridge : At this point incremental commits would be a laborious task, considering the refactoring effort involved .Do you have any other suggestions ?

@saiHemak
Copy link
Contributor Author

@alblue please review ..

@ianpartridge
Copy link
Contributor

No I don't have any suggestions - personally I find this unreviewable 😢

@pushkarnk
Copy link
Member

pushkarnk commented Sep 14, 2017

We should have the URLSession refactoring part of this PR carved out into a different PR, because the objective of that refactor is to hoist some code (into a common super class) so that it can be reused in other native protocol implementations (we have the DATA protocol still unimplemented).

@saiHemak
Copy link
Contributor Author

@pushkarnk : I have raise another PR for the URLSession refactoring [https://github.com//pull/1216].

@saiHemak saiHemak changed the title [Work In Progress] Initial implementation of FTP Initial implementation of FTP Sep 15, 2017
Copy link
Contributor

@alblue alblue left a comment

Choose a reason for hiding this comment

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

Minor observations

import Dispatch

internal let enableLibcurlDebugOutput: Bool = {
return (ProcessInfo.processInfo.environment["URLSessionDebugLibcurl"] != nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

The parenthesis around these values appear to have no value. Can you remove them, and get rid of the double-space after the return keyword?

}

func didReceive(data: Data) -> _EasyHandle._Action {
guard case .transferInProgress(var ts) = internalState else { fatalError("Received body data, but no transfer in progress.") }
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you insert a newline after the { and before the fatalError, along with } on its own line? That way the line size doesn't balloon for no reason.

}

func validateHeaderComplete(transferSate: _TransferState) -> URLResponse? {
guard transferSate.isHeaderComplete else { fatalError("Received body data, but the header is not complete, yet.") }
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

}

fileprivate func notifyDelegate(aboutReceivedData data: Data) {
guard let t = self.task else { fatalError("Cannot notify") }
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

}

func fill(writeBuffer buffer: UnsafeMutableBufferPointer<Int8>) -> _EasyHandle._WriteBufferResult {
guard case .transferInProgress(let ts) = internalState else { fatalError("Requested to fill write buffer, but transfer isn't in progress.") }
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

let dataTask1 = sesh.dataTask(with: req, completionHandler: { data, res, error in
XCTAssertNil(error)
defer { expect.fulfill() }

Copy link
Contributor

Choose a reason for hiding this comment

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

Superflous blank line

let dataTask1 = sesh.downloadTask(with: req, completionHandler: { url, res, error in
XCTAssertNil(error)
defer { expect.fulfill() }

Copy link
Contributor

Choose a reason for hiding this comment

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

Superflous blank line

let uploadTask = sesh.uploadTask(with: req, from: saveData, completionHandler: { data, res, error in
XCTAssertNil(error)
defer { expect.fulfill() }

Copy link
Contributor

Choose a reason for hiding this comment

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

Superflous blank line

waitForExpectations(timeout: 20)
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Superflous blank lines

}

extension SharedDelegate: URLSessionDownloadDelegate {
func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) {
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Superflous blank lines

@saiHemak
Copy link
Contributor Author

@alblue : Thanks for the review. I will be addressing the your comments on URL Session refactoring code through #1216

@alblue
Copy link
Contributor

alblue commented Sep 18, 2017

Sounds good - let's leave this as is for now, and after changes in #1216 come back and revisit this one?

@saiHemak
Copy link
Contributor Author

@ALBUE: Sure

@alblue
Copy link
Contributor

alblue commented Oct 16, 2017

I'm of the opinion that leaving this PR open will result in confusion between this and the current version, which is in #1216. Seeing as we've still got a way to go before that one lands, and since the content in this pull request is out of date, I recommend we close this one, get #1216 addressed, and then you can rebase the changes on your ftpimplementation branch, which will hopefully be in a smaller state by then. It will also save going back through this review history (though you can reference it from your new PR for traceability if you want) since many of the comments (especially the formatting ones) will be irrelevant by then. @saiHemak does that sound OK?

@alblue
Copy link
Contributor

alblue commented Nov 6, 2017

Closing, and deferring future changes to subsequent PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants