From 5969ae7633e6231c88669f04349b7925ac9ffb43 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Thu, 1 Mar 2018 17:09:54 +0000 Subject: [PATCH] coap_io.c: Set COAP_SOCKET_CONNECTED if connect does not complete for TCP If the non-blocking connect() does not immediately complete, when the main i/o processing loop runs and coap_read is called, coap_read_session() will assert if COAP_SOCKET_CONNECTED is not set as there will be some TLS level packets to process. If WSAEWOULDBLOCK/EINPROGRESS is returned from the connect() set COAP_SOCKET_CONNECTED in the socket flags. --- src/coap_io.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/coap_io.c b/src/coap_io.c index 316591bd..e6fb9093 100644 --- a/src/coap_io.c +++ b/src/coap_io.c @@ -312,7 +312,12 @@ coap_socket_connect_tcp1(coap_socket_t *sock, #else if (errno == EINPROGRESS) { #endif - sock->flags |= COAP_SOCKET_WANT_CONNECT; + /* + * COAP_SOCKET_CONNECTED needs to be set here as there will be reads/writes + * by underlying TLS libraries during connect() and we do not want to + * assert() in coap_read_session() or coap_write_session() when called by coap_read() + */ + sock->flags |= COAP_SOCKET_WANT_CONNECT | COAP_SOCKET_CONNECTED; return 1; } coap_log(LOG_WARNING, "coap_socket_connect_tcp1: connect: %s\n", coap_socket_strerror());