Re: RFC: BSD Socket (like) API

Leandro Pereira


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 net_context).
(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.)

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.


Join to automatically receive all group messages.