sock: extend API for asynchronous event management#8149
sock: extend API for asynchronous event management#8149miri64 wants to merge 7 commits intoRIOT-OS:masterfrom
Conversation
|
Dead-simple alternative could be (like is AFAIK planed with |
Nice. I always had sock in mind when doing the events. Maybe we can tackle two things in one API rework. I think it is time to have a generic sock type which allows application logic to be written (mostly) independently from the underlying transport. (I'm being inspired by dsock). sth like: Another very useful addition would be scatter/gather IO to allow easier stacking of protocols (e.g., websocket on https on tcp. smile please.). Something like: That way, if a very-high level protocol (e.g., json-rpc over websocket over http over tcp) provides a "struct iolist" with just one entry, every protocol below in the stack can extend that list (adding data before or after the user data), without having to re-allocate a sufficiently sized buffer for handing down to the next lower protocol in the stack. (struct iovec doesn't cut it as the array would have to be allocated at the highest level, which doesn't know the needed size). |
I know, I just wanted to convince some people other than you ;). Regarding the generic sock: I'll read your whole comment when I'm back on Monday, but for now I just wanted to say that I was also thinking of something like this (more from a lower-level point however, due to stuff like coap over UART or coap over SMS). I envisioned it more as an API on top of sock (and other APIs) instead of an API rework. As such, I would rather further discuss this in a seperate PR or (since I also think we need to discuss this a little first) issue. |
|
(also to intercept possible derailment of the discussion on asynchronouos sock). |
|
added some doc |
This reverts commit 8ed775a.
1eb5d46 to
c043fe8
Compare
|
Rebased and simplified API a bit, after some offline discussion with @kaspar030. |
|
I provided an implementation for GNRC in #8236. It is only ~100 lines of code :-). |
|
@kaspar030 can we maybe discuss your proposal for a unified |
|
Ping? Can maybe someone review this at today's Hack'n'ACK? This might be useful for the DHCPv6 implementation I plan to champion at the next IETF hackathon (mid of March). |
|
Maybe let's go through the API F2F next week? |
|
Ok, result of the F2F discussion: Implementation looks good according to @kaspar030, but the API is currently
|
|
I just worked through how to integrate the code in this PR and #8236 with gcoap. It's definitely nice to have the event abstraction and timeout handling! Given your meeting, I'll hold off on further work until you've got something to share. |
|
Good APIs are like good wine, the longer they age the better they get :P. |
@kaspar030 How can a RIOT API be too RIOT-specific? |
However, since there is again some back-chatter that implies the urgency of this matter (the initially mentioned gCoAP, the asynchronous MQTT-SN implementation by @haukepetersen, @rfuentess's inclusion of this PR into #9066, ...) and we did not look further into a "new sock" yet (at least publicly?), I'd like to put this PR again back on the table. For the an overview of the counter-arguments, please have a look at #8149 (comment). There are currently a few ideas floating around to put some traction into this:
|
What rationale is behind this? I don't see any use case for RIOT system APIs to be brought into the Linux community ... or are Linux guys urgently lacking system interfaces? @miri64 will try to look into the remaining discussion asap. |
Again, |
@miri64 I'm not saying you're wrong, I'm questioning the sense of the approach from a RIOT perspective. RIOT paper says: Which is short, but weird. POSIX is the portability standard for system APIs, not RIOT internal APIs are the portability approach to the remaining world. Of course you can always wrap things around each other and if @kaspar030 has private hobbies, that's fine. From a RIOT design perspective, it IMO makes absolutely no sense to design system APIs so that we can promote them to other OSes. Instead, technical feasibility and appropriate usefulness in the RIOT IoT context should solely guide our design. |
That is an easy choice: backward compatibility, since 2. is a crystal-clear NON-goal of the RIOT community. Changing |
|
In my opinion the ability to develop a network application on a Linux based system and being able to deploy it without modifications on RIOT is quite useful and IMHO something that could be advertised a bit more. I found it rather nice to do development on Nanocoap without having to take the RIOT environment into account, but still having some area cost guarantees as soon as it's used in RIOT.
Would it be possible to do something as is currently done with |
Perfectly agreed - that's what API standards are good for: Portability between OSes, e.g. by POSIX. And this is why we aim at POSIX compliance since the first strategy layout of RIOT in 2012. |
|
Another thing to consider, why the current approach might not be the most ideal, is that it basically fixes the user to use |
|
@miri64 fine with me: the important message was that sock will not be changed (only extended) which we agreed on in today's meeting. |
|
My understanding of this API is: You set a fixed handler and a fixed event queue for each socket and then when an "something happens" in that socket, an event gets sent to the event queue with the preset callback. How is this different to just setting a completion/reception callback (other than being able to run the callback on a different context)? Why bother with the event queue then? To me it seems as an under-utilization of the event queue capabilities.
|
|
Another question: how will this behave if there is an event already queued for a socket and while the event is still not handled more data arrives? |
|
Can we wait for my rework before we discuss this. I think most of your concerns can be addressed via the abstraction. |
|
@miri64 Sure. Anyways, I think the points I raised are equally valid for any subsystem that wants to implement an asynchronous interface (e.g async-UART, async-SAUL, etc) |
|
Yes, that's also why I think this discussion belongs somewhere else ;-). Want to open an issue? |
|
Ok, I just had an idea how to get this along a bit faster... Let's just KISS and have callbacks and clearly document that they are not supposed to be used without some kind of event management on top (which we can provide for the various ways to handle events in RIOT [ So we would would just add different event type definitions, a callback type, and a callback setter for each sock-type, e.g. typedef enum {
SOCK_EVENT_CONN_RDY = 0x0001,
SOCK_EVENT_CONN_FIN = 0x0002,
SOCK_EVENT_CONN_RCV = 0x0004,
SOCK_EVENT_MSG_RCV = 0x0010,
SOCK_EVENT_MSG_SNT = 0x0020,
SOCK_EVENT_PATH_PROP = 0x0040,
} sock_event_type_t;(ref: https://tools.ietf.org/html/draft-ietf-taps-arch-03#section-4.1.5) void (*sock_udp_cb_t)(sock_udp_t *sock, sock_event_type_t type);
void sock_udp_set_cb(sock_udp_t *sock, sock_udp_cb_t cb); |
|
I proposed this alternative approach in #11723. |
|
Again: alternative exists in #11723. Don't know, why I did not close it then. |
This is a first draft to extend the
sockAPIs for asynchronous events using theeventmodule.I kept it optionally to
sockimplementationsDoc and implementation will come as soon as I get the go from enough people.