-
Notifications
You must be signed in to change notification settings - Fork 8.2k
[WIP, 1.9] Bootstrapping BSD Sockets like API #153
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
[WIP, 1.9] Bootstrapping BSD Sockets like API #153
Conversation
|
@jukkar , @tbursztyka , @Likailiu, @simple2017 , @mike-scott : Early comments are welcome. |
1a10324 to
fcc87f2
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.
For the commit subject, I would prefer more logical naming like "net: socket: ...."
I usually try to avoid putting directory or file name into commit subject as files are moved around etc so better imho is to use logical component names here.
subsys/net/lib/Kconfig
Outdated
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.
I am fine with having a separate directory for this so we do not clutter subsys/net/ip too much.
subsys/net/lib/sockets/sockets.c
Outdated
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.
Better to use POINTER_TO_INT(ctx) here.
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.
Fixed.
Fixed, thanks. |
837e1d6 to
7512539
Compare
7512539 to
7fd742e
Compare
7fd742e to
301baee
Compare
subsys/net/lib/sockets/Kconfig
Outdated
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.
can you give an example where such namespace clashes might occur?
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.
Sure, Zephyr is being used together with a 3rd-party library, whose authors also doubted that namespace clashes would occur, so used names like "listen" and "close" in their API ;-).
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.
Can you give a specific example of such 3rd-party library? Not sure how we ever have 2 providers of bsd socket APIs, What libraries that potentially will be used with Zephyr would have implemented those APIs? This is in most cases implemented by the OS, not libraries.
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.
An example is lwIP. Another example is someone finally addressing one of the big functionality holes of Zephyr - lack of native POSIX port.
Not sure how we ever have 2 providers of bsd socket APIs, What libraries that potentially will be used with Zephyr would have implemented those APIs?
I'm not sure either, and that's good indication that best practices of namespacing should be followed, otherwise we get a situation of a crowd where everyone considers oneself exceptional and that problems of everyone else doesn't apply to them, and if they happen, it's somebody else's chore to resolve them.
This is in most cases implemented by the OS, not libraries.
Zephyr is itself a library (libzephyr.a) which real applications (consisting of many other libraries) use to get some hardware abstraction and multitasking. Maybe in a couple of decades it'll become "the OS", but standing in a big-big crowd and pretending it's the only thing isn't the smoothest way to get there ;-).
Let's again take lwIP as an example. It defines 2 related config params:
#if LWIP_COMPAT_SOCKETS
#define accept(a,b,c) lwip_accept(a,b,c)
#define bind(a,b,c) lwip_bind(a,b,c)
...
#if LWIP_POSIX_SOCKETS_IO_NAMES
#define read(a,b,c) lwip_read(a,b,c)
#define write(a,b,c) lwip_write(a,b,c)
#define close(s) lwip_close(s)
...
#endif
#endif
As the paragraph on which you comment describes, close() alone is enough to decide - it's irresponsible to grab that name for a code which doesn't do all that normal close() does, then it should be prefixed, then everything else should be prefixed for consistency.
6924216 to
d958aaa
Compare
This adds Kconfig and build infrastructure and implements zsock_socket() and zsock_close() functions. Signed-off-by: Paul Sokolovsky <[email protected]>
Two changes are required so far: * There's unavoidable need to have a per-socket queue of packets (for data sockets) or pending connections (for listening sockets). These queues share the same space (as a C union). * There's a need to track "EOF" status of connection, synchronized with a queue of pending packets (i.e. EOF status should be processed only when all pending packets are processed). A natural place to store it per-packet then, and we had a "sent" bit which was used only for outgoing packets, recast it as "eof" for incoming socket packets. Signed-off-by: Paul Sokolovsky <[email protected]>
With CONFIG_NET_SOCKETS_POSIX_NAMES=y, "raw" POSIX names like socket(), recv(), close() will be exposed (using macro defines). The close() is the biggest culprit here, because in POSIX it applies to any file descriptor, but in this implementation - only to sockets. Signed-off-by: Paul Sokolovsky <[email protected]>
By moving user_data member at the beginning of structure. With refcount at the beginning, reliable passsing of contexts via FIFO was just impossible. (Queuing contexts to a FIFO is required for BSD Sockets API). Signed-off-by: Paul Sokolovsky <[email protected]>
TODO: Should really go to kernel.h. Signed-off-by: Paul Sokolovsky <[email protected]>
Signed-off-by: Paul Sokolovsky <[email protected]>
Signed-off-by: Paul Sokolovsky <[email protected]>
Signed-off-by: Paul Sokolovsky <[email protected]>
Signed-off-by: Paul Sokolovsky <[email protected]>
Signed-off-by: Paul Sokolovsky <[email protected]>
Signed-off-by: Paul Sokolovsky <[email protected]>
If a socket is closed without reading all data from peer or accepting all pending connection, they will be leaked. So, flush queues explicitly. Signed-off-by: Paul Sokolovsky <[email protected]>
d958aaa to
287230f
Compare
|
Closing in favor of #498, which is resubmit of the complete patchset suitable for wide review. Hopefully, initial comments here were address and/or answered. |
NEWLIB_LIBC_NANO was defined only for gnuarmemb toolchain because Zephyr SDK did not support the newlib nano variant (as defined by nano.specs) due to the inherent limitations of crosstool-ng, which is used to build the toolchains. Since crosstool-ng/crosstool-ng#1279 added support for the nano C/C++ runtime library variant and this change was introduced to the Zephyr SDK through zephyrproject-rtos#153, it is no longer necessary to restrict the newlib nano variant to gnuarmemb toolchain only. Signed-off-by: Stephanos Ioannidis <[email protected]>
This shows the very initial steps on moving BSD Sockets API (prototyped out of tree) into the tree.
Things to decide/ack: