gnrc_sock: provide asynchronous event implementation#12625
gnrc_sock: provide asynchronous event implementation#12625miri64 merged 2 commits intoRIOT-OS:masterfrom
Conversation
f6b2d48 to
1bddd1d
Compare
1bddd1d to
5b8d499
Compare
|
Rebased to current master. |
5b8d499 to
9d36513
Compare
|
And updated |
9d36513 to
734da1c
Compare
|
And fixed some flubs pointed out by Murdock and I noticed myself. |
|
So I am trying to use this, but even with |
Yes, you have to select |
|
And don't include RIOT/tests/gnrc_sock_async/main.c Lines 125 to 127 in 734da1c A normal user is supposed to use an API like the ones proposed (but still under construction) in #12601 or #12602. |
|
Ah, OK. So this is not quite ready. It also begins to feel like it's quite a bit of overhead, since I just need something that gives me |
If its done, it will provide |
|
It looks like That doesn't seem immediately useful - I would much rather have an event when a |
a) you can't guarantee that |
That was just an example. The event should be generated when it's actually possible to send a new datagram, what this is dependent on is specific to the implementation. But what is When adding asynchronous events, a "stack is ready to accept new datagram" event would be the least to ask for IMHO. |
The use case is to only call functions when they are supposed to (similar to
This is the case once the a) the packet is put into the lower layer thread's IPC message queue (which accept when it is empty ensures that it can handle more packets), |
I can confirm now, that this still works (see #12678). |
|
Ping? |
benpicco
left a comment
There was a problem hiding this comment.
Code looks good, just two small things.
The name of sock_ip_get_async_ctx() is confusing. It's not a getter for async_ctx but a general access wrapper.
Not sure if it is even necessary, just makes the code slightly nicer to read. But then it might as well be static inline so the nicer syntax doesn't come at a cost.
I also don't know what a "proper sock_async frontend" would look like, so if I were to use the API I'd just copy the code from the example test.
| sock_async_ctx_t *sock_ip_get_async_ctx(sock_ip_t *sock) | ||
| { | ||
| return &sock->reg.async_ctx; | ||
| } |
There was a problem hiding this comment.
Where would async_ctx be set?
The function name confused me. I thought this was a getter, but it just returns a pointer to the field in the struct and the user can then do with it whatever they want.
Wouldn't sock_ip_async_ctx() be a less confusing name then?
Since this is just a 'nicer' way to access a field of the sock_ip_t, it should better be a static inline function so the compiler can optimize it away.
There was a problem hiding this comment.
The function is part of the sock_async API so its name is already merged. However
Code looks good, just two small things.
The name ofsock_ip_get_async_ctx()is confusing. It's not a getter forasync_ctxbut a general access wrapper.
Not sure if it is even necessary, just makes the code slightly nicer to read. But then it might as well bestatic inlineso the nicer syntax doesn't come at a cost.
As far as I know this is a getter. So I don't know why the name is confusing.
Since this is just a 'nicer' way to access a field of the
sock_ip_t, it should better be astatic inlinefunction so the compiler can optimize it away.
sock_ip_t is defined by the network stack, so different for any network stack. An inline is thus not easily possible. Edit: Also it is not just a "nicer" way, but the only legal way to access the async_ctx for the socket. With anything else you break yourself the abstraction and you've got yourself the same problem we have with the current gcoap all over again (see #8130)
There was a problem hiding this comment.
So is the idea to set async_ctx by calling *sock_ip_get_async_ctx(sock) = ctx; ?
And where is async_ctx defined to begin with?
There was a problem hiding this comment.
So is the idea to set
async_ctxby calling*sock_ip_get_async_ctx(sock) = ctx;?
And where isasync_ctxdefined to begin with?
You don't set the context. It is just a helper for the frontend to have a storage type within the sock and get it from the sock stack-indepent. Have a look at #12601 and #12602. For #12601 async_ctx is just a kernel_pid_t and sock_ip_get_async_ctx() returns a pointer to that position within the sock object (so setting happens by dereferencing the pointer). For #12602 it is the event + pointer to the queue, so setting just happens by providing values for the members.
There was a problem hiding this comment.
I see, so this is not to be used/useful on it's own, but part of a larger feature.
I'd drop the #ifdef SOCK_HAS_ASYNC_CTX bits as those are never used and wouldn't even compile right now, but I see how it's convenient to not have that commit in two PRs.
There was a problem hiding this comment.
I'd drop the
#ifdef SOCK_HAS_ASYNC_CTXbits as those are never used and wouldn't even compile right now, but I see how it's convenient to not have that commit in two PRs.
I don't get what you mean by that. What do you propose to do if the front-end does not need a context?
There was a problem hiding this comment.
It's not about the #ifdef, it's that sock_async_ctx_t is not defined anywhere in current master or this PR.
There was a problem hiding this comment.
Ah, so you miss the implementation ;-P
benpicco
left a comment
There was a problem hiding this comment.
Code looks good and tescase runs.
I find 'future use' code always a bit hard to review, but you're maintaining that subsystem, you'll know best what to do with it 😉.
Divide and conquer ;-) |
| arduino-nano \ | ||
| arduino-uno \ | ||
| atmega328p \ | ||
| nucleo-f031k6 \ |
There was a problem hiding this comment.
| nucleo-f031k6 \ | |
| nucleo-f031k6 \ | |
| nucleo-f042k6 \ |
734da1c to
23428ab
Compare
Contribution description
This provides an implementation for GNRC for the asynchronous event management for
sock_ipandsock_udpas provided in #11723.Testing procedure
Tests are provided with this PR
Issues/PRs references
Follow-up on #11723
Requires
#12624(merged) to work.