BSD Sockets like API: prototyping report #2


Paul Sokolovsky
 

This messaged continues from "BSD Sockets like API: prototyping
report #1".

Notes/issues:

1. The most complex function to implement was of course recv(), that's
where "push to pull" API style conversion happens. Beyond the initial
version pushed to MicroPython master, I went on to optimize it as if it
was a part of in-stack impl, and faced number of issues, per my weekend
mails to the list. These changes are in a separate branch,
https://github.com/pfalcon/micropython/commits/zephyr-socket

2. send() was easy, but only superficially. At BUD17 min-summit,
Tomasz told few times that current issue of Zephyr buffer management
is that it mixes low-level data chunking (into net_buf's) with
network-level chunking of user data into MTU units. I wasn't sure I
understand that, but now I see the issue very well. Actually, I don't
see where MTU chunking happens at all. As far as I can see,
net_nbuf_append(), passed 10K of data, will happily create a network
packet with so many fragments (as long as it'll get that many
fragments), but what force will send out such a monster? Note that if
it won't get that many fragments, it will stop abruptly and won't even
tell how much data it processed. That's vividly not POSIXly and
ticketed as https://jira.zephyrproject.org/browse/ZEP-1984

3. Wrapping other functions was trivial, but some of them have
non-POSIX behavior in corner (but easy to hit) cases, e.g. for bind() -
https://jira.zephyrproject.org/browse/ZEP-1644

4. Back to recv(), not everything is happy either. I don't see how my
socket implementation could affect TCP flow control, and that needs to
be done by sockets (and not existing push-style IP stack) to avoid being
DoSed with too much packets. I'd take lwIP's solution of letting the
application to advance TCP receive window as a proven one, and on which
MicroPython's lwIP socket module is based.

5. Further steps: implement listen()/accept() for sever-side
functionality (listen easy, accept is again hard, push-to-pull
conversion).


I'm going to do more homework on each of the issues above first, and
then send separate mails if no suitable solution found, though if
someone has a quick feedback now, I'll appreciate it.

--
Best Regards,
Paul

Linaro.org | Open source software for ARM SoCs
Follow Linaro: http://www.facebook.com/pages/Linaro
http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog

Join devel@lists.zephyrproject.org to automatically receive all group messages.