From 4d9fbbf4219127511e94f6b509aa1d87ff8b3ae0 Mon Sep 17 00:00:00 2001 From: Neko Life Date: Sun, 1 Dec 2024 10:52:19 +0000 Subject: [PATCH] fix/sslclient-spinlock (#1339) --- src/dpp/sslclient.cpp | 5 ----- src/dpp/wsclient.cpp | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/dpp/sslclient.cpp b/src/dpp/sslclient.cpp index 454f9517c2..c40820df0a 100644 --- a/src/dpp/sslclient.cpp +++ b/src/dpp/sslclient.cpp @@ -373,11 +373,6 @@ void ssl_client::on_read(socket fd, const struct socket_events& ev) { } void ssl_client::on_write(socket fd, const struct socket_events& e) { - /* We wanted to write before so keep it */ - socket_events new_se{e}; - new_se.flags |= WANT_WRITE; - owner->socketengine->update_socket(new_se); - if (!tcp_connect_done) { tcp_connect_done = true; } diff --git a/src/dpp/wsclient.cpp b/src/dpp/wsclient.cpp index 328b5d8d8e..1c2ef3763d 100644 --- a/src/dpp/wsclient.cpp +++ b/src/dpp/wsclient.cpp @@ -129,6 +129,23 @@ void websocket_client::write(const std::string_view data, ws_opcode _opcode) ssl_client::socket_write(header); ssl_client::socket_write(data); } + + bool should_append_want_write = false; + socket_events *new_se = nullptr; + { + std::lock_guard lk(owner->socketengine->fds_mutex); + auto i = owner->socketengine->fds.find(sfd); + + should_append_want_write = i != owner->socketengine->fds.end() && (i->second->flags & WANT_WRITE) != WANT_WRITE; + if (should_append_want_write) { + new_se = i->second.get(); + new_se->flags |= WANT_WRITE; + } + } + + if (should_append_want_write) { + owner->socketengine->update_socket(*new_se); + } } bool websocket_client::handle_buffer(std::string& buffer)