From 8f05cf02b2667ef8ed7aaba4b51b08d81652491e Mon Sep 17 00:00:00 2001 From: Neko-Life Date: Tue, 26 Nov 2024 22:51:48 +0700 Subject: [PATCH] fix: initial stuff, still not working --- src/dpp/cluster.cpp | 6 +++++- src/dpp/socketengines/epoll.cpp | 1 + src/dpp/voice/enabled/read_write.cpp | 4 ---- src/dpp/voice/enabled/write_ready.cpp | 14 +++++++++----- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/dpp/cluster.cpp b/src/dpp/cluster.cpp index 604deff496..1b934cd8cd 100644 --- a/src/dpp/cluster.cpp +++ b/src/dpp/cluster.cpp @@ -311,7 +311,11 @@ void cluster::shutdown() { /* Signal termination */ terminating = true; if (engine_thread) { - engine_thread->join(); + if (engine_thread->joinable()) { + engine_thread->join(); + } else { + log(ll_warning, "Cluster engine_thread is not joinable on dtor"); + } } { std::lock_guard l(timer_guard); diff --git a/src/dpp/socketengines/epoll.cpp b/src/dpp/socketengines/epoll.cpp index cfde495d94..c330cd4255 100644 --- a/src/dpp/socketengines/epoll.cpp +++ b/src/dpp/socketengines/epoll.cpp @@ -111,6 +111,7 @@ struct DPP_EXPORT socket_engine_epoll : public socket_engine_base { } if ((ev.events & EPOLLOUT) != 0U) { + /* Should we have a flag to allow keeping WANT_WRITE? Maybe like WANT_WRITE_ONCE or GREEDY_WANT_WRITE, eh */ eh->flags = modify_event(epoll_handle, eh, eh->flags & ~WANT_WRITE); if (eh->on_write) { eh->on_write(fd, *eh); diff --git a/src/dpp/voice/enabled/read_write.cpp b/src/dpp/voice/enabled/read_write.cpp index 5512f08c1c..fd41423796 100644 --- a/src/dpp/voice/enabled/read_write.cpp +++ b/src/dpp/voice/enabled/read_write.cpp @@ -39,10 +39,6 @@ void discord_voice_client::send(const char* packet, size_t len, uint64_t duratio } else [[unlikely]] { this->udp_send(packet, len); } - if (!this->sent_stop_frames) { - udp_events.flags = WANT_READ | WANT_WRITE | WANT_ERROR; - owner->socketengine->update_socket(udp_events); - } } int discord_voice_client::udp_send(const char* data, size_t length) { diff --git a/src/dpp/voice/enabled/write_ready.cpp b/src/dpp/voice/enabled/write_ready.cpp index 385388c356..6877a97c26 100644 --- a/src/dpp/voice/enabled/write_ready.cpp +++ b/src/dpp/voice/enabled/write_ready.cpp @@ -31,6 +31,13 @@ namespace dpp { void discord_voice_client::write_ready() { + /* + * WANT_WRITE has been reset everytime this method is being called, + * ALWAYS set it again no matter what we're gonna do. + */ + udp_events.flags = WANT_READ | WANT_WRITE | WANT_ERROR; + owner->socketengine->update_socket(udp_events); + uint64_t duration = 0; bool track_marker_found = false; uint64_t bufsize = 0; @@ -54,15 +61,12 @@ void discord_voice_client::write_ready() { } } if (!outbuf.empty()) { - if (this->udp_send(outbuf[0].packet.data(), outbuf[0].packet.length()) == (int)outbuf[0].packet.length()) { + int sent_siz = this->udp_send(outbuf[0].packet.data(), outbuf[0].packet.length()); + if (sent_siz == (int)outbuf[0].packet.length()) { duration = outbuf[0].duration * timescale; bufsize = outbuf[0].packet.length(); outbuf.erase(outbuf.begin()); } - if (!outbuf.empty()) { - udp_events.flags = WANT_READ | WANT_WRITE | WANT_ERROR; - owner->socketengine->update_socket(udp_events); - } } } }