-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Basic NSURLSession implementation #299
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
Conversation
// testCase(TestNSValue.allTests), | ||
// testCase(TestNSUserDefaults.allTests), | ||
// testCase(TestNSXMLParser.allTests), | ||
// testCase(TestNSXMLDocument.allTests), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
obviously these will all have to be re-enabled before merging is considered.
I should note that this relies on https://github.com/apple/swift-corelibs-libdispatch — and it has an extremely rudimentary version of NSOperationQueue to support the delegate queue on |
CFURLSession_EasyCodeNO_CONNECTION_AVAILABLE, // CURLE_NO_CONNECTION_AVAILABLE | ||
CFURLSession_EasyCodeSSL_PINNEDPUBKEYNOTMATCH, // CURLE_SSL_PINNEDPUBKEYNOTMATCH | ||
CFURLSession_EasyCodeSSL_INVALIDCERTSTATUS, // CURLE_SSL_INVALIDCERTSTATUS | ||
} CFURLSession_EasyCode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is worth noting that when porting to Linux these will not be exported in the same manner as enums on Darwin. We have numerous other examples that show the #if os(OSX) || os(iOS)
re-export as constant pattern that must be done. it might be worthwhile to modify that script that generates these to generate those as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I’ll deal with that once libdispatch lands for Linux — until then it won’t compile either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this to avoid using enum
in C.
per the NSOQ stub (and other dispatch usage) we are still waiting on libdispatch to completely land; hopefully before then I will have some more things for NSOQ that will give a decent implementation for something more complete than what you have so far. |
f9dd2c3
to
85abca1
Compare
9d087d0
to
63a7b48
Compare
Question: What changes should be done on this before it can be merged back into master? Also, I'd like feedback on the fact that |
We're still working on dispatch; it's certainly the plan for it to be available. We should proceed as if it'll be there in the end. I'm ok with splitting implementation into multiple files as well. Thanks for your work on this @danieleggert. |
I’ve split it into these files
|
@@ -2150,6 +2226,7 @@ | |||
r, | |||
r, | |||
); | |||
OTHER_SWIFT_FLAGS = "-DDEPLOYMENT_ENABLE_LIBDISPATCH"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably leave this out until everything is ready to go right?
I'd like to double check a few things:
Once we're set, we'll squash merge this in so we can work on it iteratively after that (including enabling on Linux). |
@parkera This all assumes that libdispatch is available on Linux — we’ll have to hold off until then. I’ll do a few more tweaks to this tomorrow and the day after and then squash everything into a single commit. One option would be to add the old version of |
6d3cb17
to
836b865
Compare
It’s all squashed into a single commit now, but I might keep working on this. |
d639e9c
to
6f151ae
Compare
6f151ae
to
05bcbcd
Compare
@danieleggert Conflicts :( |
//===----------------------------------------------------------------------===// | ||
/// | ||
/// \file | ||
/// This file contains wrappes / helpers to import libcurl into Swift. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo here (wrappers)
I’ll make sure conflicts get resolved once libdispatch is working. |
@danieleggert Is this pull request ready to merge? |
any updates on this PR? |
@danieleggert Thanks for your work on this. I believe it's been merged as part of the later work. |
@parkera Do we know which release of swift will have this content merged in? |
It's in Swift 3 actually. Give it a shot and let us know on the mailing lists if you have any problems. |
@sgharms The main content went into Swift 3, and there's been some addition bug fixes in the 3.0.1 previews. There's still some missing function - particularly things like task cancellation. Having people "kick the tires" and provide tests for anything that doesn't work would be really useful. |
My apologies for slow reply here. I went on vacation 😎 . Let me admit that there's a great chance I'm exposing my profound ignorance here, so I hope I'll not embarrass myself too much. My Environment
Code import Foundation
let config = URLSessionConfiguration.default // Session Configuration
let session = URLSession(configuration: config) // Load configuration into Session
let url = URL(string: "http://apple.com")!
let task = session.dataTask(with: url, completionHandler: {
(data, response, error) in
print("Callback ran")
})
task.resume()
print("End of line") OutputEnd of line ErrorI never see "Callback ran" ConclusionBased on the stack trace it would seem to me that using Swift to accomplish basic HTTP operations is not supported on my platform. |
As supplement, I asked someone with 3.0 Mac to run the same code and got the following: I suspect the (suspended) note indicates that Playgrounds isn't working with the async call? In any case, I find the behavior in both situations surprising and didn't see warnings around this mentioned in the guide. Am I missing something? |
@sgharms I am assuming you are running this in the CLI in linux. well, the request doesn't get fired because the program has already exited. You need to maintain the program running until (at least) the request has had a chance to run to see the results. Look into NSRunLoop or dispatch_main(). At least one of them should be available in Linux's Swift environment |
Ah! OK. I had wrongly assumed that there was a default run loop that would make sure all the spawned tasks closed. Thanks. |
[SKSwiftPMWorkspace] Set swiftpm config file when creating Workspace
I'm creating this pull request to get feedback on my implementation so far.
There are still many TODOs in the code, but it’s far along enough to evaluate the architecture and design I have chosen for this task. I’ve tried to outline quite a bit in the code itself in form of comments. Please let me know:
The
NSURLSession.swift
file has a NSURLSession API implementation overview.As for testing, I'm hoping to spend quite a bit of time on building an in-process HTTP server to better test some of the desired behaviour. Particularly when testing things such as different payloads, headers, and
POST
/PUT
requests that's the only way to get good testing.I'd like to split the
NSURLSession+libcurl.swift
file into multiple smaller files, but that'd break with the existing style. Any thoughts?The
CFURLSessionInterface.{c,h}
files are very verbose in order to not expose libcurl directly. This was suggested by @phausler and @rothomp3 — but I'm not sure if this is what they were hoping for.All unimplemented code should still be marked with
NSUnimplemented()
where applicable.This does not at all try to implement so-called background session which would have
to rely on a system daemon to perform HTTP requests white the app is not running (either
suspended or terminated). Such code would have to rely on IPC and the launchd equivalent
on the platform it is running on.