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

Allow Kitura-NIO to only listen on one network address #205

Merged
merged 4 commits into from
May 24, 2019
Merged

Allow Kitura-NIO to only listen on one network address #205

merged 4 commits into from
May 24, 2019

Conversation

TaborKelly
Copy link
Contributor

@TaborKelly TaborKelly commented May 16, 2019

Description

@billabt was nice enough to add support for this at the BlueSocket layer here. However, I really want to use that functionality to fix Kitura/Kitura#1450.

I also have code ready to go for Kitura/Kitura-net#299 and Kitura.

Obviously, this is the Kitura-NIO version of the Kitura-Net change.

Motivation and Context

This is necessary to close Kitura/Kitura#1450. Should I open another issue for Kitura-NIO?

How Has This Been Tested?

Manual testing by myself. I also modified the test harness to use the new code path.

Checklist:

  • I have submitted a CLA form
  • If applicable, I have updated the documentation accordingly.
  • If applicable, I have added tests to cover my changes.

try listen(.tcp(port, node))
}

@available(*, deprecated, message: "use 'listen(on:node) throws' instead")
Copy link
Contributor

@pushkarnk pushkarnk May 17, 2019

Choose a reason for hiding this comment

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

I'm not sure if we should deprecate listen(on:). We could make this a simple additive change by introducing a new listen(on:node) or listen(on:address). Or better have a default value for node/address

- Parameter delegate: The delegate handler for HTTP connections.

- Returns: A new instance of a `HTTPServer`.
*/
public static func listen(on port: Int, delegate: ServerDelegate?) throws -> ServerType {
public static func listen(on port: Int, node: String?, delegate: ServerDelegate?) throws -> ServerType {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have the node/address parameter have a default value of nil? To make sure this is not a breaking change.

@@ -26,20 +26,40 @@ public protocol Server {
/// Port number for listening for new connections.
var port: Int? { get }

/// Has the same meaning as in `getaddrinfo()`.
var node: String? { get }
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we call this address?

/// A server state.
var state: ServerState { get }

/// Listen for connections on a socket.
///
/// - Parameter on: port number for new connections (eg. 8080)
/// - Parameter node: has the same meaning as in `getaddrinfo()`
func listen(on port: Int, node: String?) throws
Copy link
Contributor

Choose a reason for hiding this comment

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

Repeat: node can have a default value of nil

/// Listen for connections on a socket.
///
/// - Parameter on: port number for new connections (eg. 8080)
@available(*, deprecated, message: "use 'listen(on:node) throws' with instead")
Copy link
Contributor

Choose a reason for hiding this comment

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

repeat: can we avoid deprecation here?

@@ -58,6 +58,9 @@ public class HTTPServer: Server {
/// The TCP port on which this server listens for new connections. If `nil`, this server does not listen on a TCP socket.
public private(set) var port: Int?

/// Has the same meaning as in `getaddrinfo()`.
public private(set) var node: String?
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we call this address please?

Copy link
Contributor

@pushkarnk pushkarnk left a comment

Choose a reason for hiding this comment

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

Looks good. I request a couple of changes though:

  1. As commented by @djones6 on the Kitura-net PR can we have node renamed as address?
  2. All the new versions of listen() can be changed to include a new address parameter with the default value of nil. This is to make sure the change isn't breaking and there is no need to deprecate existing API method.

Update: Realised it isn't possible to have default parameter values with protocols, which can be worked around using extensions. At the least, we must make this a non breaking change i.e. we must add the new listen versions without deprecating the existing ones.

2. Remove extra code.
@TaborKelly
Copy link
Contributor Author

I believe that my latest changes fix everything that was requested and bring this PR in line with the one for Kitura-Net. Let me know if I missed anything.

- Parameter address: The address of the network interface to listen on. Defaults to nil, which means this server
will listen on all interfaces.
*/
public func listen(on port: Int, address: String?) throws {
Copy link
Contributor

Choose a reason for hiding this comment

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

This must match the Kitura-net version:
public func listen(on port: Int, address: String? = nil) throws {

- Parameter delegate: The delegate handler for HTTP connections.

- Returns: A new instance of a `HTTPServer`.
*/
public static func listen(on port: Int, delegate: ServerDelegate?) throws -> ServerType {
public static func listen(on port: Int, address: String?, delegate: ServerDelegate?) throws -> ServerType {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same feedback here. This must match Kitura-net:
public static func listen(on port: Int, address: String? = nil, delegate: ServerDelegate?) throws -> HTTPServer

Copy link
Contributor

@pushkarnk pushkarnk left a comment

Choose a reason for hiding this comment

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

@TaborKelly Just a couple of more comments around the parity (with Kitura-net) of the two listen() methods.

public func listen(on port: Int) throws {
/// - Parameter address: The address of the network interface to listen on. Defaults to nil, which means this
/// server will listen on all interfaces.
public func listen(on port: Int, address: String?) throws {
Copy link
Contributor

Choose a reason for hiding this comment

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

Although FastCGI is not implemented yet, the function signature should still be consistent with Kitura-net (as per @pushkarnk 's comments on HTTPServer) - need to add the default nil value.

/// - Parameter delegate: the delegate handler for FastCGI/HTTP connections
///
/// - Returns: a new `FastCGIServer` instance
public static func listen(on port: Int, delegate: ServerDelegate?) throws -> FastCGIServer {
public static func listen(on port: Int, address: String?, delegate: ServerDelegate?) throws -> FastCGIServer {
Copy link
Contributor

Choose a reason for hiding this comment

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

(same here)

@TaborKelly
Copy link
Contributor Author

Good catch. I missed that since they conformed to the same Server protocol.

@pushkarnk pushkarnk merged commit 61b29ed into Kitura:master May 24, 2019
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.

Kitura listens on every available address/interface
3 participants