Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

extmod/modlwip,esp32,unix: Add support for socket recv flags argument#17312

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

projectgus
Copy link
Contributor

@projectgusprojectgus commentedMay 16, 2025
edited
Loading

Summary

Goal of this PR is to have support for theMSG_DONTWAIT andMSG_PEEK flags for socketrecv &recvfrom on unix, esp32, and all "bare metal" LWIP ports.

  • Bare metal LWIP adds support for these flags in modlwip.c, with some refactoring to try and reduce the code size impact.
  • esp32 port now passes these flags through to the LWIP BSD socket layer, which already supports them.
  • unix port already had support for flags argument.MSG_PEEK constant is now exposed to Python code.
  • Adds multi_net tests for the new flags.
  • Adds docs for theflags argument.

Note: Zephyr & CC3200 ports have their ownsocket module implementations, support not added to these yet. Zephyr looks like it would be trivially easy, CC3200 I didn't look into.

Testing

  • Ran new and existing multi_net tests on ESP32_GENERIC_S3, RPI_PICO2_W, RPI_PICO_W and PYBD_SF2 boards. One outstanding issue that seems lower level than these changes, seecomment.

Trade-offs and Alternatives

  • Support forMSG_PEEK is motivated by wanting to improve the DTLS support. AddingMSG_DONTWAIT as well was relatively easy, and both of these flags are potentially useful for socket programming on MicroPython. However I guess the obvious alternative is not to add them, or to implement them via a Python wrapper in the Python socket module (which would be hacky but possible).

AmirHmZz reacted with thumbs up emoji
@projectgusprojectgus added port-esp32 extmodRelates to extmod/ directory in source port-unix port-rp2 labelsMay 16, 2025
@github-actionsGitHub Actions
Copy link

Code size report:

   bare-arm:    +0 +0.000% minimal x86:    +0 +0.000%    unix x64:   +56 +0.007% standard[incl +32(data)]      stm32:    +0 +0.000% PYBV10     mimxrt:    +0 +0.000% TEENSY40        rp2:   +32 +0.003% RPI_PICO_W       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS  qemu rv32:    +0 +0.000% VIRT_RV32

@codecovCodecov
Copy link

codecovbot commentedMay 16, 2025
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.54%. Comparing base(4dff9cb) to head(ba92063).
Report is 6 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@##           master   #17312   +/-   ##=======================================  Coverage   98.54%   98.54%           =======================================  Files         169      169             Lines       21898    21898           =======================================  Hits        21579    21579             Misses        319      319

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report?Share it here.

🚀 New features to boost your workflow:
  • ❄️Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@dpgeorgedpgeorge left a comment

Choose a reason for hiding this comment

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

This looks good, thanks!

I tested on ESP8266, RPI_PICO2_W-RISCV and ESP32_GENERIC, and all the new tests pass.

@projectgusprojectgusforce-pushed thefeature/socket_recv_peek branch from2308215 to3c2eaf3CompareMay 30, 2025 02:15
@projectgus
Copy link
ContributorAuthor

projectgus commentedMay 30, 2025
edited
Loading

Have updated the tests and run on various ports (updated in description), but have found what looks like a lower level issue on RPI_PICO_W and RPI_PICO2_W.

The newudp_recv_dontwait.py test fails when instance0 is one of these rp2 boards. The UDPrecv succeeds, then UDPsendto() appears to succeed and the frame appears to be passed into the CYW43 module ("ETHTX" is shown in the trace), but packet capture shows it is almost never sent (maybe <10% of the time it sends). Unclear why, other tests show occasional packet loss but nothing consistent like this.

@projectgusprojectgusforce-pushed thefeature/socket_recv_peek branch from3c2eaf3 to14f7f61CompareMay 30, 2025 02:28
@projectgus
Copy link
ContributorAuthor

projectgus commentedMay 30, 2025
edited
Loading

The UDPrecv succeeds, then UDPsendto() appears to succeed and the frame appears to be passed into the CYW43 module ("ETHTX" is shown in the trace), but packet capture shows it is almost never sent

One interesting thing in the output withwlan.config(trace=0xFF) is that the runs which succeed are always:

  1. ETHRX (first UDP packet from instance1)
  2. ETHTX (UDP packet sent)
  3. ETHRX (second UDP packet from instance1)

But the runs which fail always seem to be:

  1. ETHRX (first UDP packet from instance1)
  2. ETHRX (second UDP packet from instance1)
  3. ETHTX (UDP packet "sent" but not seen in the packet capture)

Weirdly this ordering seems to be happening internal to the CYW43 module, packet captures of successful runs on the Wi-Fi AP always show the second ordering over the air (RX, RX, TX) even though the trace log shows (RX, TX, RX).

@projectgusprojectgusforce-pushed thefeature/socket_recv_peek branch 3 times, most recently from355ef35 to7f76f49CompareMay 30, 2025 05:38
@projectgusprojectgus requested a review fromdpgeorgeMay 30, 2025 06:11
Implements MSG_PEEK and MSG_DONTWAIT.This work was funded through GitHub Sponsors.Signed-off-by: Angus Gratton <angus@redyak.com.au>
Implements MSG_PEEK and MSG_DONTWAIT (both passed through to LWIPsockets API).This work was funded through GitHub Sponsors.Signed-off-by: Angus Gratton <angus@redyak.com.au>
This work was funded through GitHub Sponsors.Signed-off-by: Angus Gratton <angus@redyak.com.au>
Adds TCP and UDP multi_net test cases.This work was funded through GitHub Sponsors.Signed-off-by: Angus Gratton <angus@redyak.com.au>
Adding multi_net case for UDP only, as TCP timing is hard to test reliably.Signed-off-by: Angus Gratton <angus@redyak.com.au>
Implementation added for various ports in the parent commits.This work was funded through GitHub Sponsors.Signed-off-by: Angus Gratton <angus@redyak.com.au>
Copy link
Member

@dpgeorgedpgeorge left a comment

Choose a reason for hiding this comment

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

I've re-reviewed this, it looks good.

I also tested on PYBD_SF2, RPI_PICO_W and ESP32_GENERIC. The new tests all pass, and so do existing ones (with known failures).

@dpgeorgedpgeorgeforce-pushed thefeature/socket_recv_peek branch from7f76f49 toba92063CompareJune 3, 2025 02:56
@dpgeorgedpgeorge merged commitba92063 intomicropython:masterJun 3, 2025
67 checks passed
@projectgusprojectgus deleted the feature/socket_recv_peek branchJune 5, 2025 01:47
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@dpgeorgedpgeorgedpgeorge approved these changes

Assignees
No one assigned
Labels
extmodRelates to extmod/ directory in sourceport-esp32port-rp2port-unix
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@projectgus@dpgeorge

[8]ページ先頭

©2009-2025 Movatter.jp