-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
Reported by Paul Sokolovsky:
Support for BSD Sockets like API for Zephyr was one of the most common request among stakeholders and parties interested in Zephyr, and for a long time. At the Zephyr meeting at OpenSummit Portland 2017 and Zephyr Mini-summit at Budapest 2017 it was confirmed that there're no stakeholders who oppose the idea, and then Linaro Zephyr team would like to proceed with prototyping and implementing this API.
This Epic is created to collect initial ideas/requirements, as well to keep interested parties in loop. It may be somewhat informal at this time, and may be rewritten to follow a more formal pattern if requested.
The current basic ideas are:
-
Implementation of BSD Sockets would be a pilot project of adding POSIX-compatible APIs to Zephyr, which is another popular requested from parties interested in Zephyr.
-
However, the initial target is to implement "BSD Socket compatible API", without pledging for full/almost full POSIX compliance from the start. The underlying requirements is that the new API still followed Zephyr paradigm of being lightweight. As a specific example, BSD Sockets compatible API may be implemented similarly to how Winsock is (was) implemented on Windows systems - while the underlying system isn't POSIX compliant, Wisock API is still largely BSD Sockets compatible, allowing to easily port existing apps.
-
The new API is a separate layer, not intended to supersede or replace native Zephyr networking API. This is because it's already clear that BSD Sockets API will require more resources (e.g. it's not zero-copy friendly, while native Zephyr is). Implementation-wise, there however should be work on making native API behaviors more POSIX compliant, to avoid cases when BSD Sockets compatible functions need to be coded "from scratch" or require a lot of adaptation code due to differences in behavior (this is a specific point from [~anasnashif] and how we already tried to do it for 1.7.0 release).
-
The initial prototyping would be done out of tree (using a sample application requiring BSD Sockets APII), with an existing native networking API. Experience gathered during this process will be used to submit an RFC how to implement the needed functionality in a more optimal way natively in Zephyr.
More technical points/details:
-
The main difference between native Zephyr API and BSD Sockets is "push" vs "pull" API paradigm: on reception, Zephyr API "pushes" packets to an application via a callback, while BSD Sockets (and POSIX API in general) lets an app "pull" data from an OS when the app needs it. So, majority of work (and the main initial focus) will be on "impedance matching" two API models. This will require a buffering queue for incoming packets. Zephyr has such a queue, but it is global, for all interface and network contexts, while BSD Sockets will require it per-socket.
-
The initial focus is just on connection/sending/receiving calls. More advanced features like select()/poll() (waiting for multiple sockets) is subject for next stage of work (it will require more deep thinking on how to architect POSIX API layer, as those calls aren't specific to sockets, but are generic for file descriptor objects).
-
Initial prototyping is to happen using MicroPython, as it already has a module which implements push-style API in terms of pull-style API, and allows for easy testing as it provides scripting language to exercise these APIs.
- BSD Sockets API: Offloading support #3706: BSD Sockets API: Offloading support
- BSD Sockets API: Select/poll API #3664: BSD Sockets API: Select/poll API
- BSD Sockets API: Non-blocking API #3663: BSD Sockets API: Non-blocking API
- BSD Sockets API: Basic blocking API #3662: BSD Sockets API: Basic blocking API
(Imported from Jira ZEP-1921)