Created
May 25, 2020 18:34
-
-
Save pokgak/416ee56cb306e1c63739f1dfc3789d1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/examples/dtls-echo/dtls-client.c b/examples/dtls-echo/dtls-client.c | |
index baa5d9291..4f38df2ac 100644 | |
--- a/examples/dtls-echo/dtls-client.c | |
+++ b/examples/dtls-echo/dtls-client.c | |
@@ -59,6 +59,9 @@ static int _events_handler(struct dtls_context_t *ctx, | |
(void) ctx; | |
(void) session; | |
(void) level; | |
+ if (code == DTLS_EVENT_CONNECT) { | |
+ puts("EVENT CONNECT"); | |
+ } | |
if (code == DTLS_EVENT_CONNECTED) { | |
dtls_connected = 1; | |
diff --git a/pkg/tinydtls/contrib/sock_dtls.c b/pkg/tinydtls/contrib/sock_dtls.c | |
index 5bd3f6bd5..9cc12c29b 100644 | |
--- a/pkg/tinydtls/contrib/sock_dtls.c | |
+++ b/pkg/tinydtls/contrib/sock_dtls.c | |
@@ -109,7 +109,10 @@ static int _event(struct dtls_context_t *ctx, session_t *session, | |
(void)session; | |
sock_dtls_t *sock = dtls_get_app_data(ctx); | |
- msg_t msg = { .type = code }; | |
+ msg_t msg = { | |
+ .type = code, | |
+ .content.ptr = session, | |
+ }; | |
#ifdef ENABLE_DEBUG | |
switch (code) { | |
case DTLS_EVENT_CONNECT: | |
@@ -123,7 +126,9 @@ static int _event(struct dtls_context_t *ctx, session_t *session, | |
break; | |
} | |
#endif /* ENABLE_DEBUG */ | |
- mbox_put(&sock->mbox, &msg); | |
+ if (code != DTLS_EVENT_CONNECT) { | |
+ mbox_put(&sock->mbox, &msg); | |
+ } | |
#ifdef SOCK_HAS_ASYNC | |
if (sock->async_cb != NULL) { | |
switch(code) { | |
@@ -132,7 +137,6 @@ static int _event(struct dtls_context_t *ctx, session_t *session, | |
break; | |
case DTLS_EVENT_CONNECTED: { | |
dtls_peer_t *peer = dtls_get_peer(ctx, session); | |
- DEBUG("sock_dtls: event connected\n"); | |
if (peer->role == DTLS_SERVER) { | |
/* we are server so a client connected */ | |
sock->async_cb(sock, SOCK_ASYNC_CONN_RDY, | |
@@ -473,6 +477,8 @@ ssize_t sock_dtls_recv(sock_dtls_t *sock, sock_dtls_session_t *remote, | |
} | |
else if (mbox_try_get(&sock->mbox, &msg) && | |
msg.type == DTLS_EVENT_CONNECTED) { | |
+ memcpy(&remote->dtls_session, msg.content.ptr, sizeof(session_t)); | |
+ | |
if (sock->async_cb) { | |
sock_async_flags_t flags = SOCK_ASYNC_CONN_RDY; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment