-
Notifications
You must be signed in to change notification settings - Fork 125
Support NIO Transport Services #135
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
Support NIO Transport Services #135
Conversation
Can one of the admins verify this patch? |
2 similar comments
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
6a53611
to
11dacad
Compare
self.eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) | ||
#if canImport(Network) | ||
if #available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *) { | ||
self.eventLoopGroup = NIOTSEventLoopGroup() |
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.
@weissi do you think it's a good idea to default to TS on darwin?
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.
Yes
var bootstrap: ClientTransportBootstrap | ||
|
||
if #available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *) { | ||
bootstrap = NIOTSConnectionBootstrap(group: self.eventLoopGroup) |
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.
why not channelEL ?? delegateEL
?
let loopGroup: EventLoopGroup | ||
let external: EventLoopGroup | ||
|
||
#if canImport(Network) |
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.
maybe we should extract this to a test helper function (that returns one ELG)?
ping @Yasumoto this is now ready :) |
how this works is: You only need one #if canImport(Network)
// Creating the "universal bootstrap" with the `NIOSSLClientTLSProvider`.
let tlsProvider = NIOTSClientTLSProvider(tlsOptions: .init())
let bootstrap = NIOTSClientTLSProvider(NIOTSEventLoopGroup(group: group), tls: tlsProvider)
#else
// TLS setup.
let configuration = TLSConfiguration.forClient()
let sslContext = try NIOSSLContext(configuration: configuration)
// Creating the "universal bootstrap" with the `NIOSSLClientTLSProvider`.
let tlsProvider = NIOSSLClientTLSProvider<ClientBootstrap>(context: sslContext, serverHostname: "example.com")
let bootstrap = NIOClientTCPBootstrap(ClientBootstrap(group: group), tls: tlsProvider)
#endif
// Bootstrapping a connection using the "universal bootstrapping mechanism"
let connection = bootstrap.enableTLS()
.connect(host: "example.com", port: 12345)
.wait() For AsyncHTTPClient, you'll want to cache two bootstraps:
and then you can just use the right one to bootstrap connections from depending on if that's TLS or not. |
Oh heck yah 💪 |
Hey guys, I have tested it with aws-sdk-swift and it works on both macOS and iOS. Should I open another PR? |
+1 the sooner we get the special Darwin treatment out of |
@adam-fowler amazing! If you’ve already got a branch ready for review let’s close this out and transition to a new PR 🙇 |
This is the continuation of the good work of @Yasumoto and @weissi in #135 The following code adds support for NIO Transport services. When the ConnectionPool asks for a connection bootstrap it is returned a NIOClientTCPBootstrap which wraps either a NIOTSConnectionBootstrap or a ClientBootstrap depending on whether the EventLoop we are running on is NIOTSEventLoop. If you initialize an HTTPClient with eventLoopGroupProvider set to .createNew then if you are running on iOS, macOS 10.14 or later it will provide a NIOTSEventLoopGroup instead of a EventLoopGroup. Currently a number of tests are failing. 4 of these are related to the NIOSSLUncleanShutdown error the others all seem related to various race conditions which are being dealt with on other PRs. I have tested this code with aws-sdk-swift and it is working on both macOS and iOS. Things look into: The aws-sdk-swift NIOTS HTTP client had issues with on Mojave. We should check if this is the case for async-http-client as well. Co-authored-by: Joe Smith <yasumoto7@gmail.com> Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
This is the investigation for #127
This builds on apple/swift-nio#1253 and apple/swift-nio-transport-services#65, mostly motivated by soto-project/soto-core#141.
Caveats:
ChannelOptions.maxMessagesPerRead
; we'll need this to make sure we don't block intestUploadStreamingBackpressure
.NIOTSEventLoopGroup
if it's available. We should likely also add a check if we're passed in a.shared()
EventLoop that we use the corresponding bootstrap, but figured I'd post this up here for an initial review first.