From: Matt Corallo Date: Sun, 3 Oct 2021 21:41:18 +0000 (+0000) Subject: [net] Ensure we don't spin loop by keeping the poll write bit set X-Git-Tag: v0.0.102.0^2~6 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=b1ea57acc81af14e8623deca4a8a352d0d2ff71e;p=ldk-c-bindings [net] Ensure we don't spin loop by keeping the poll write bit set Previously we'd not been unsetting POLLOUT, which will result in us spin-loop'ing with ChannelManager_write_buffer_space_avail. Further, we'd also not been unsetting the POLLIN bit, which would result in us never pausing read as the SocketDescriptor API requires us to. --- diff --git a/ldk-net/ldk_net.c b/ldk-net/ldk_net.c index dc19e8e..f404ddd 100644 --- a/ldk-net/ldk_net.c +++ b/ldk-net/ldk_net.c @@ -111,10 +111,9 @@ static uintptr_t sock_send_data(void* desc, struct LDKu8slice data, bool resume_ for (int i = 0; i < descriptor->handler->sockcount; i++) { if (descriptor->handler->pollfds[i].fd == descriptor->fd) { if (pause_read) { - descriptor->handler->pollfds[i].events &= POLLIN; - descriptor->handler->pollfds[i].events |= POLLOUT; + descriptor->handler->pollfds[i].events = POLLOUT; } else { - descriptor->handler->pollfds[i].events |= POLLIN; + descriptor->handler->pollfds[i].events = POLLIN; } break; } @@ -243,8 +242,7 @@ static void *sock_thread_fn(void* arg) { lockres = pthread_mutex_lock(&handler->sockets_mutex); assert(lockres == 0); assert(handler->pollfds[i - 1].fd == pollfds[i].fd); // Only we change fd order! - handler->pollfds[i - 1].events &= POLLIN; - handler->pollfds[i - 1].events |= POLLOUT; + handler->pollfds[i - 1].events = POLLOUT; lockres = pthread_mutex_unlock(&handler->sockets_mutex); assert(lockres == 0); }