From 8c635e709ba1e88dba4bfd3255e04a9ff466089a Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Mon, 21 Sep 2020 12:19:12 +0100 Subject: [PATCH] epoll: Stop spin between TCP connect and received data If a client TCP connection connects, EPOLLOUT remains enabled so epoll_wait() always returns immediately causing a loop until there is other data traffic. This fix is to enable EPOLLIN and disable EPOLLOUT if COAP_SOCKET_WANT_WRITE is not set at point of connection successful. --- src/net.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/net.c b/src/net.c index ccbf0157..061c7569 100644 --- a/src/net.c +++ b/src/net.c @@ -1696,6 +1696,9 @@ coap_io_do_epoll(coap_context_t *ctx, struct epoll_event *events, size_t nevents (events[j].events & (EPOLLOUT|EPOLLERR|EPOLLHUP|EPOLLRDHUP))) { sock->flags |= COAP_SOCKET_CAN_CONNECT; coap_connect_session(session->context, session, now); + if (!(sock->flags & COAP_SOCKET_WANT_WRITE)) { + coap_epoll_ctl_mod(sock, EPOLLIN, __func__); + } } if ((sock->flags & COAP_SOCKET_WANT_READ) &&