-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
Reported by Paul Sokolovsky:
Some feedback on playing with network API, for a case of TCP:
#1.
Comment in net_context.c:net_context_tcp_init():
{code}
* If we are called by net_receive() first, then
* we are working as a server, if net_send() called
* us first, then we are the client.
*/
{code}
Sorry, but that's quite an arbitrary restriction. There's nothing wrong with a server which speaks to client first on connection, or client which waits data from server. Trying to lump up together who speaks first and server/client side is against established networking practices and can lead only to confusion.
#2:
The same net_context.c:net_context_tcp_init() tries to hide standard socket-like operations LISTEN, CONNECT behind adhoc facade. Why? uIP's interface is more high-level/familiar then than Zephyr's.
#3:
Native uIP API functions like tcp_connect() acquired "struct net_buf *buf" argument. Again, it's unclear why - standard socket API's "connect" operation doesn't involve any (application) data sending.
#4:
net_send()'s operation and return values are confusing. For example, given Zephyr's workflow, a client would create a context, and call net_send(). net_send() will call tcp_connect() eventually, and socket will be guaranteedly in "connection in progress" state, so net_send() will return -EINPROGRESS and put net_buf into the queue to be sent out eventually. So, now an application guaranteedly gets -EINPROGRESS on first call to net_send() and ends up with net_buf it has no idea what to do? Should it be unref'ed? Or not? How much is that useful? Probably not much, what's useful is: a) create socket; b) establish connection (either block until it's done, or be able to query state for non-blocking socket); c) proceed to send data. That's how standard socket paradigm works (as implemented by uIP too), and unfortunately not how Z networking works.
So, I don't know how useful is such feedback. My usecase: be able to write/port networking applications written in standard manner to Zephyr. I understand that a requirement for Zephyr might have been "provide simplified means of network programming", but when dealing with a well-established and already simple area like network programming (with sockets being prevalent paradigm), there's fine order between "simplification" and "deterioration".
So, for my usage, using underlying uIP API is more beneficial than Z's facade on top of it. But it's no going to easy due to Z's patching of classical uIP API. Now I'll be looking how to "undo" Z layer and get back to uIP classics.
Thanks for listening.
(Imported from Jira ZEP-741)