[riot-notifications] [RIOT-OS/RIOT] sock/async: add function to retrieve session object of current DTLS event (#15755)

Martine Lenders notifications at github.com
Thu Jan 14 01:44:42 CET 2021


@miri64 commented on this pull request.



> @@ -87,6 +87,7 @@ static int _read(struct dtls_context_t *ctx, session_t *session, uint8_t *buf,
     sock->buffer.session = session;
 #ifdef SOCK_HAS_ASYNC
     if (sock->async_cb != NULL) {
+        memcpy(&sock->async_cb_session, session, sizeof(session_t));

> Okay apparently I misunderstood how `sock_async` works. Although it seems that `sock->async_cb` is called inside of `_event`/`_read`, it is actually executed after leaving those functions. I discovered this after adding some printf. Can you confirm this @miri64?

Mhh there are actually two callbacks, that's maybe where the confusion is coming from. `sock->async_cb` is the asynchronous callback internal to the `sock_async` backend and then there is the frontend's callback (since `sock_async_event` also uses callbacks) which is called from the event handler (to make things portable between different frontend approaches including a bare metal approach of just using the backend they have the same signature). `sock->async_cb` is called from within `_event` and `_read` that is correct, but it merely triggers the frontend event (`event_post()` in the `sock_async_event` case). The actual event handling is done within the the event handler of the frontend, which will be (comparably) much later then the call to `sock->async_cb` and in a different thread (the medium priority thread of `event_thread` in `tests/pkg_tinydtls_sock_async`'s case. Hope that clears things

TL;DR passing pointers around breaks the asynchronous and decoupled nature of `sock_async`. @janosbrodbeck was right in copying the session instead.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/15755#discussion_r556971179
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210113/7740f23a/attachment.htm>


More information about the notifications mailing list