-
Notifications
You must be signed in to change notification settings - Fork 24
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
Conversation
try listen(.tcp(port, node)) | ||
} | ||
|
||
@available(*, deprecated, message: "use 'listen(on:node) throws' instead") |
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'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 { |
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.
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 } |
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.
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 |
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.
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") |
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.
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? |
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.
Can we call this address
please?
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.
Looks good. I request a couple of changes though:
- As commented by @djones6 on the
Kitura-net
PR can we havenode
renamed asaddress
? - All the new versions of
listen()
can be changed to include a newaddress
parameter with the default value ofnil
. 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.
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 { |
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.
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 { |
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.
Same feedback here. This must match Kitura-net:
public static func listen(on port: Int, address: String? = nil, delegate: ServerDelegate?) throws -> HTTPServer
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.
@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 { |
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.
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 { |
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.
(same here)
Kitura-Net exactly.
Good catch. I missed that since they conformed to the same Server protocol. |
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: