Re: RFC: BSD Socket (like) API

Paul Sokolovsky

Hello Leandro,

On Tue, 28 Mar 2017 09:08:51 -0700
Leandro Pereira <> wrote:


On 03/27/2017 04:16 AM, Paul Sokolovsky wrote:

2- FDs just waste memory, add locking and make things harder to
debug, use socket structures.
Agree. That was one of the 1st question I got at the minisummit,
and my answer was: "well, we could waste some memory by adding the
FD table to map small integers to underlying structures, but why?".
Indeed, by just casting pointers to integers, we can go a long,
long way of using this API and porting existing apps.
Right now we have memory pools, so file descriptors could be really
an index to the net_context pool. Since FDs should be treated as
opaque identifiers, this should continue to be fine even if things
change in the future (such as having multiple mempools for struct
Sounds like an interesting idea, thanks for sharing, I'll keep it in
mind and will look into it at later stage.

(We might need a queue per context to properly emulate
the read() API, though, so the reference might not be exactly to a
net_context pool, but the same idea applies.)
Right, that's exactly what I'm working on right now. Well, I keep this
per-context queue external so far, but later we'll need to see whether
we want to introduce a separate "socket" object type to host it (and
any other needed fields), or if we can (configurably!) embed them in
net_context. If we agree with the idea that a particular app will use
either native API, or BSD Sockets API, I think this latter choice is
very viable.

Casting a pointer to an integer as suggested might work, but will
most likely be an issue with the common pattern of checking for error
by just comparing the sign of the return value, instead of the
(technically correct) comparison with -1.
Yep, we'd need to look at the corpus of apps to be ported to Zephyr to
see how grave that issue is. That may take some time (to collect needed
set), though if you have any related data/ideas already, please share


Best Regards,
Paul | Open source software for ARM SoCs
Follow Linaro:!/linaroorg -

Join to automatically receive all group messages.