diff --git a/server/src/client/ConnectedClientTextCommandHandler.cpp b/server/src/client/ConnectedClientTextCommandHandler.cpp index abc7a3a..5de51bf 100644 --- a/server/src/client/ConnectedClientTextCommandHandler.cpp +++ b/server/src/client/ConnectedClientTextCommandHandler.cpp @@ -9,7 +9,6 @@ #include "../music/MusicBotManager.h" #include "../client/music/MusicClient.h" #include "../client/voice/VoiceClient.h" -#include "./ConnectedClient.h" using namespace ts; using namespace ts::server; diff --git a/server/src/client/query/QueryClient.cpp b/server/src/client/query/QueryClient.cpp index 9a38a84..6935f3c 100644 --- a/server/src/client/query/QueryClient.cpp +++ b/server/src/client/query/QueryClient.cpp @@ -355,8 +355,9 @@ void QueryClient::handle_event_write(int fd, short, void *ptr_client) { } } +/* The +1 to identify the syscall */ +constexpr static auto kReadBufferLength{1024 * + 1}; void QueryClient::handle_event_read(int fd, short, void *ptr_client) { - static const size_t kReadBufferLength = 1024 * 8; uint8_t buffer[kReadBufferLength]; auto client = (QueryClient*) ptr_client; @@ -364,7 +365,7 @@ void QueryClient::handle_event_read(int fd, short, void *ptr_client) { auto length = read(fd, buffer, kReadBufferLength); if(length <= 0) { /* error handling */ - if(length == -1 && errno == EAGAIN) { + if(length < 0 && errno == EAGAIN) { /* Nothing to read */ return; } diff --git a/server/src/client/voice/PacketEncoder.cpp b/server/src/client/voice/PacketEncoder.cpp index 24c1ac1..69c647c 100644 --- a/server/src/client/voice/PacketEncoder.cpp +++ b/server/src/client/voice/PacketEncoder.cpp @@ -322,9 +322,15 @@ bool PacketEncoder::pop_write_buffer(protocol::OutgoingServerPacket *&result) { void PacketEncoder::reenqueue_failed_buffer(protocol::OutgoingServerPacket *packet) { std::lock_guard wlock{this->write_queue_mutex}; + if(packet->next || &packet->next == this->send_queue_tail || &packet->next == this->encrypt_queue_tail) { + /* packets seemed to gotten reenqueued already */ + return; + } + if(!this->send_queue_head) { this->send_queue_tail = &packet->next; } + packet->next = this->send_queue_head; this->send_queue_head = packet; } diff --git a/server/src/client/web/WSWebClient.cpp b/server/src/client/web/WSWebClient.cpp index 0bcc727..917b186 100644 --- a/server/src/client/web/WSWebClient.cpp +++ b/server/src/client/web/WSWebClient.cpp @@ -62,17 +62,17 @@ void WebClient::handleMessageWrite(int fd, short, void *ptr_client) { event_add(client->writeEvent, nullptr); } +/* The +2 to identify the syscall */ +constexpr static auto kReadBufferSize{1024 * 4 + 2}; void WebClient::handleMessageRead(int fd, short, void *ptr_client) { auto client = dynamic_pointer_cast(((WebClient*) ptr_client)->ref()); assert(client); - size_t buffer_length = 1024 * 4; - uint8_t buffer[buffer_length]; - - auto length = recv(fd, buffer, buffer_length, MSG_NOSIGNAL | MSG_DONTWAIT); + uint8_t buffer[kReadBufferSize]; + auto length = recv(fd, buffer, kReadBufferSize, MSG_NOSIGNAL | MSG_DONTWAIT); if(length <= 0) { /* error handling "slow path" */ - if(length == 0 && errno == EAGAIN) { + if(length < 0 && errno == EAGAIN) { /* We've currently no data queued */ return; }