Skip to content
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

Launching Services with existing NWConnection or NWListener objects #156

Merged
merged 3 commits into from
Sep 21, 2022

Conversation

carolinacass
Copy link
Contributor

NIO Transport Services is not capable of launching services with existing NWConnection or NWListener objects. Being able to get an existing NWConnection through a connection bootstrap and into a channel is a useful capability for advanced use cases.

Modifications:

  • Added an option to bootstrap with existing NWListener and NWConnection
  • Completed promise connection earlier within NIOTSChannels when AlreadyConfigured is called
  • Added test with new NWConnection and NWListener to register Channels

Result:
Able to create and register a channel using an existing NWListener and NWConnection

NIO Transport Services is not capable of launching services with existing NWConnection or NWListener objects. Being able to get
an existing NWConnection through a connection bootstrap and into a channel is a useful capability for advanced use cases.

Modifications:
* Added an option to bootstrap with existing NWListener and NWConnection
* Completed promise connection earlier within NIOTSChannels when AlreadyConfigured is called
* Added test with new NWConnection and NWListener to register Channels

Result:
Able to create and register a channel using an existing NWListener and NWConnection
@swift-server-bot
Copy link

Can one of the admins verify this patch?

5 similar comments
@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@Lukasa Lukasa added the semver/minor Adds new public API. label Sep 20, 2022
@Lukasa
Copy link
Collaborator

Lukasa commented Sep 20, 2022

@swift-server-bot add to allowlist

Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Great, this generally looks really good! Just a few notes left in the diff.

@@ -205,7 +219,11 @@ public final class NIOTSConnectionBootstrap {
initializer(conn)
}.flatMap {
conn.eventLoop.assertInEventLoop()
return conn.register()
if shouldRegister{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if shouldRegister{
if shouldRegister {

Sources/NIOTransportServices/NIOTSListenerBootstrap.swift Outdated Show resolved Hide resolved
tcpOptions: tcpOptions,
tlsOptions: tlsOptions,
childLoopGroup: childLoopGroup,
childChannelQoS:childChannelQoS,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
childChannelQoS:childChannelQoS,
childChannelQoS: childChannelQoS,

tlsOptions: tlsOptions,
childLoopGroup: childLoopGroup,
childChannelQoS:childChannelQoS,
childTCPOptions:childTCPOptions,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
childTCPOptions:childTCPOptions,
childTCPOptions: childTCPOptions,

childLoopGroup: childLoopGroup,
childChannelQoS:childChannelQoS,
childTCPOptions:childTCPOptions,
childTLSOptions:childTLSOptions
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
childTLSOptions:childTLSOptions
childTLSOptions: childTLSOptions

let buffer = connection.allocator.bufferFor(string: "hello, world!")
let completeFuture = connection.expectRead(buffer)
connection.writeAndFlush(buffer, promise: nil)
// this is the assert that matters to make sure it works writes data
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// this is the assert that matters to make sure it works writes data
// this is the assert that matters to make sure it works & writes data

@@ -526,7 +555,7 @@ class NIOTSEndToEndTests: XCTestCase {
.connect(to: address)
.wait()) { error in
print(error)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
}
}

/// Use a pre-existing `NWConnection` to connect a `Channel`.
///
/// - parameters:
/// - connection: The NWConnection path to wrap.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// - connection: The NWConnection path to wrap.
/// - connection: The NWConnection to wrap.

/// Bind the `NIOTSListenerChannel` to an existing `NWListener`.
///
/// - parameters:
/// - listener: The NWListener path to bind.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// - listener: The NWListener path to bind.
/// - listener: The NWListener to wrap.

@@ -128,6 +128,28 @@ internal final class NIOTSListenerChannel {
// Must come last, as it requires self to be completely initialized.
self._pipeline = ChannelPipeline(channel: self)
}

/// Create a `NIOTSConnectionChannel` with an already-established `NWListener`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// Create a `NIOTSConnectionChannel` with an already-established `NWListener`.
/// Create a `NIOTSListenerChannel` with an already-established `NWListener`.

@Lukasa Lukasa merged commit 5cd6fd4 into apple:main Sep 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants