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 UDP multicast. #618
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -331,12 +331,29 @@ public enum ChannelError: Error { | |
} | ||
|
||
/// This should be inside of `ChannelError` but we keep it separate to not break API. | ||
// TODO: For 2.0: bring this inside of `ChannelError` | ||
// TODO: For 2.0: bring this inside of `ChannelError`. https://github.com/apple/swift-nio/issues/620 | ||
public enum ChannelLifecycleError: Error { | ||
/// An operation that was inappropriate given the current `Channel` state was attempted. | ||
case inappropriateOperationForState | ||
} | ||
|
||
/// This should be inside of `ChannelError` but we keep it separate to not break API. | ||
// TODO: For 2.0: bring this inside of `ChannelError`. https://github.com/apple/swift-nio/issues/620 | ||
public enum MulticastError: Error { | ||
/// The local address of the `Channel` could not be determined. | ||
case unknownLocalAddress | ||
|
||
/// The address family of the multicast group was not valid for this `Channel`. | ||
case badMulticastGroupAddressFamily | ||
|
||
/// The address family of the provided multicast group join is not valid for this `Channel`. | ||
case badInterfaceAddressFamily | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question as above |
||
|
||
/// An attempt was made to join a multicast group that does not correspond to a multicast | ||
/// address. | ||
case illegalMulticastAddress(SocketAddress) | ||
} | ||
|
||
extension ChannelError: Equatable { | ||
public static func ==(lhs: ChannelError, rhs: ChannelError) -> Bool { | ||
switch (lhs, rhs) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftNIO open source project | ||
// | ||
// Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
/// A `MulticastChannel` is a `Channel` that supports IP multicast operations: that is, a channel that can join multicast | ||
/// groups. | ||
/// | ||
/// - note: As with `Channel`, all operations on a `MulticastChannel` are thread-safe. | ||
public protocol MulticastChannel: Channel { | ||
/// Request that the `MulticastChannel` join the multicast group given by `group`. | ||
/// | ||
/// - parameters: | ||
/// - group: The IP address corresponding to the relevant multicast group. | ||
/// - promise: The `EventLoopPromise` that will be notified once the operation is complete, or | ||
/// `nil` if you are not interested in the result of the operation. | ||
func joinGroup(_ group: SocketAddress, promise: EventLoopPromise<Void>?) | ||
|
||
/// Request that the `MulticastChannel` join the multicast group given by `group` on the interface | ||
/// given by `interface`. | ||
/// | ||
/// - parameters: | ||
/// - group: The IP address corresponding to the relevant multicast group. | ||
/// - interface: The interface on which to join the given group, or `nil` to allow the kernel to choose. | ||
/// - promise: The `EventLoopPromise` that will be notified once the operation is complete, or | ||
/// `nil` if you are not interested in the result of the operation. | ||
func joinGroup(_ group: SocketAddress, interface: NIONetworkInterface?, promise: EventLoopPromise<Void>?) | ||
|
||
/// Request that the `MulticastChannel` leave the multicast group given by `group`. | ||
/// | ||
/// - parameters: | ||
/// - group: The IP address corresponding to the relevant multicast group. | ||
/// - promise: The `EventLoopPromise` that will be notified once the operation is complete, or | ||
/// `nil` if you are not interested in the result of the operation. | ||
func leaveGroup(_ group: SocketAddress, promise: EventLoopPromise<Void>?) | ||
|
||
/// Request that the `MulticastChannel` leave the multicast group given by `group` on the interface | ||
/// given by `interface`. | ||
/// | ||
/// - parameters: | ||
/// - group: The IP address corresponding to the relevant multicast group. | ||
/// - interface: The interface on which to leave the given group, or `nil` to allow the kernel to choose. | ||
/// - promise: The `EventLoopPromise` that will be notified once the operation is complete, or | ||
/// `nil` if you are not interested in the result of the operation. | ||
func leaveGroup(_ group: SocketAddress, interface: NIONetworkInterface?, promise: EventLoopPromise<Void>?) | ||
} | ||
|
||
|
||
// MARK:- Default implementations for MulticastChannel | ||
public extension MulticastChannel { | ||
func joinGroup(_ group: SocketAddress, promise: EventLoopPromise<Void>?) { | ||
self.joinGroup(group, interface: nil, promise: promise) | ||
} | ||
|
||
func joinGroup(_ group: SocketAddress) -> EventLoopFuture<Void> { | ||
let promise: EventLoopPromise<Void> = self.eventLoop.newPromise() | ||
self.joinGroup(group, promise: promise) | ||
return promise.futureResult | ||
} | ||
|
||
func joinGroup(_ group: SocketAddress, interface: NIONetworkInterface?) -> EventLoopFuture<Void> { | ||
let promise: EventLoopPromise<Void> = self.eventLoop.newPromise() | ||
self.joinGroup(group, interface: interface, promise: promise) | ||
return promise.futureResult | ||
} | ||
|
||
func leaveGroup(_ group: SocketAddress, promise: EventLoopPromise<Void>?) { | ||
self.leaveGroup(group, interface: nil, promise: promise) | ||
} | ||
|
||
func leaveGroup(_ group: SocketAddress) -> EventLoopFuture<Void> { | ||
let promise: EventLoopPromise<Void> = self.eventLoop.newPromise() | ||
self.leaveGroup(group, promise: promise) | ||
return promise.futureResult | ||
} | ||
|
||
func leaveGroup(_ group: SocketAddress, interface: NIONetworkInterface?) -> EventLoopFuture<Void> { | ||
let promise: EventLoopPromise<Void> = self.eventLoop.newPromise() | ||
self.leaveGroup(group, interface: interface, promise: promise) | ||
return promise.futureResult | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
should this also take the family as parameter (just like we did for
notAMulticastAddress
) ?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 could, but it would really need both the channel address family and the provided address family to make much sense. Should we do that?
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.
Nah... I think that would be too much :) Ship it !