-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
extmod/modlwip: Implement a queue of incoming UDP/raw packets #17261
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
extmod/modlwip: Implement a queue of incoming UDP/raw packets #17261
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #17261 +/- ##
=======================================
Coverage 98.54% 98.54%
=======================================
Files 169 169
Lines 21896 21896
=======================================
Hits 21578 21578
Misses 318 318 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Code size report: |
23c2be6 to
06826a5
Compare
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.
Implementation and test look solid to me. I have a couple of minor comment suggestions for future reference, but that's all.
extmod/modlwip.c
Outdated
| #define MOD_NETWORK_SOCK_DGRAM (2) | ||
| #define MOD_NETWORK_SOCK_RAW (3) | ||
|
|
||
| // Total queue length for UDP/raw connections. |
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.
| // Total queue length for UDP/raw connections. | |
| // Total queue length for buffered UDP/raw incoming packets. |
(That's right, isn't it?)
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.
Yes, that's right. Comment updated.
extmod/modlwip.c
Outdated
| struct pbuf *pbuf; | ||
| } tcp; | ||
|
|
||
| // UDP and raw sockets have a queue of incoming pbuf's. |
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.
| // UDP and raw sockets have a queue of incoming pbuf's. | |
| // UDP and raw sockets have a queue of incoming pbuf's, implemented as a ringbuffer |
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.
Updated.
extmod/modlwip.c
Outdated
|
|
||
| // UDP and raw sockets have a queue of incoming pbuf's. | ||
| struct { | ||
| uint8_t iget; |
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.
| uint8_t iget; | |
| uint8_t iget; // Ringbuffer read index |
(and same for iput)
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.
Updated for both lines.
The bare-metal lwIP socket interface is currently quite limited when used for UDP streams, because it only allows one outstanding incoming UDP packet. If one UDP packet is waiting to be socket.recv'd and another one comes along, then the second one is simply dropped. This commit implements a queue for incoming UDP and raw packets. The queue depth is fixed at compile time, and is currently 4. This allows better use of UDP connections, eg more efficient. It also makes DTLS work better which sometimes has a queue of UDP packets (eg during the connection phase). Signed-off-by: Damien George <damien@micropython.org>
This commit adds a new network multi-test which sends a burst of UDP packets from the client, and the server doesn't recv them until they have all been sent. Signed-off-by: Damien George <damien@micropython.org>
06826a5 to
a05766f
Compare
Summary
The bare-metal lwIP socket interface is currently quite limited when used for UDP streams, because it only allows one outstanding incoming UDP packet. If one UDP packet is waiting to be
socket.recv'd and another one comes along, then the second one is simply dropped.This PR implements a queue for incoming UDP and raw packets. The queue depth is fixed at compile time, and is currently 4.
This allows better use of UDP connections, eg more efficient. It also makes DTLS work better which sometimes has a queue of UDP packets (eg during the connection phase).
Testing
A new network multi-test is added which sends a burst of UDP packets from the client, and the server doesn't
recvthem until they have all been sent.Tested on PYBD-SF2 and RPI_PICO2_W. The new test passes (it fails without the UDP queue added here).
Also tested on unix and ESP32_GENERIC, both of which pass (they already have a UDP queue).
Trade-offs and Alternatives