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

feat: add multicast UDP listener support #412

Merged
merged 10 commits into from
Nov 7, 2022

Conversation

leki75
Copy link
Contributor

@leki75 leki75 commented Oct 17, 2022

1. Are you opening this pull request for bug-fixes, optimizations or new feature?

New feature

2. Please describe how these code changes achieve your intention.

This PR is intended to support UDP multicast listeners. Whenever a user wants to bind to a UDP multicast address one needs to provide additional setsockopt calls to make it work.

3. Please link to the relevant issues (if any).

4. Which documentation changes (if any) need to be made/updated because of this PR?

Additional configuration option: WithMuticastInterfaceIndex.
Examples:

gnet.Run(echo, "udp://224.0.0.100:8765"))

or

iface, _ := net.InterfaceByName("eth0")
gnet.Run(echo, "udp://224.0.0.100:8765"), gnet.WithMulticastInterfaceIndex(iface.Index))

4. Checklist

  • I have squashed all insignificant commits.
  • I have commented my code for explaining package types, values, functions, and non-obvious lines.
  • I have written unit tests and verified that all tests passes (if needed).
  • I have documented feature info on the README (only when this PR is adding a new feature).
  • (optional) I am willing to help maintain this change if there are issues with it later.

Copy link
Owner

@panjf2000 panjf2000 left a comment

Choose a reason for hiding this comment

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

Thanks for this feature, please add some tests for it.

@codecov
Copy link

codecov bot commented Nov 3, 2022

Codecov Report

Base: 71.26% // Head: 71.42% // Increases project coverage by +0.16% 🎉

Coverage data is based on head (aca68c9) compared to base (20ff40b).
Patch coverage: 100.00% of modified lines in pull request are covered.

❗ Current head aca68c9 differs from pull request most recent head 91f25e7. Consider uploading reports for the commit 91f25e7 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #412      +/-   ##
==========================================
+ Coverage   71.26%   71.42%   +0.16%     
==========================================
  Files          13       13              
  Lines        1392     1428      +36     
==========================================
+ Hits          992     1020      +28     
- Misses        328      335       +7     
- Partials       72       73       +1     
Flag Coverage Δ
unittests 71.42% <100.00%> (+0.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
listener.go 100.00% <100.00%> (ø)
options.go 94.87% <100.00%> (+0.27%) ⬆️
gnet.go 71.22% <0.00%> (-3.34%) ⬇️
connection.go 66.14% <0.00%> (+0.94%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

listener.go Outdated Show resolved Hide resolved
@panjf2000
Copy link
Owner

Based on the failures on Linux runners, it seemed that there is no expected loopback interface with multicast support on Github Linux runners, whereas there is on macOS runners, so I assume we need to skip these tests when the OS is Linux?

@leki75 leki75 closed this Nov 7, 2022
@leki75 leki75 reopened this Nov 7, 2022
@leki75
Copy link
Contributor Author

leki75 commented Nov 7, 2022

Sorry for making so many changes. It is hard to write a test that runs both on Linux and Mac. The interface names and capabilities differ. Eg. the loopback interface name is lo0 and the multicast flag is set on Mac, while it is lo on Linux and the flag is not set. Writing a universal networking library is really hard! My appreciation.

@panjf2000
Copy link
Owner

Sorry for making so many changes. It is hard to write a test that runs both on Linux and Mac. The interface names and capabilities differ. Eg. the loopback interface name is lo0 and the multicast flag is set on Mac, while it is lo on Linux and the flag is not set. Writing a universal networking library is really hard! My appreciation.

Don't worry about it, all these commits will be squashed into one commit finally.

gnet_test.go Show resolved Hide resolved
@panjf2000 panjf2000 added enhancement New feature or request proposal Proposal for this repo pending merged This PR has been reviewed and approved proposal accepted Proposal has been accepted labels Nov 7, 2022
@panjf2000 panjf2000 merged commit ad9986e into panjf2000:dev Nov 7, 2022
@panjf2000
Copy link
Owner

Thanks~

0-haha pushed a commit to 0-haha/gnet that referenced this pull request Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pending merged This PR has been reviewed and approved proposal accepted Proposal has been accepted proposal Proposal for this repo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants