Some minor optimizations

This commit is contained in:
WolverinDEV 2021-04-22 10:50:48 +02:00
parent 03a0cec60e
commit 05f834b47d
4 changed files with 14 additions and 8 deletions

View File

@ -9,7 +9,6 @@
#include "../music/MusicBotManager.h" #include "../music/MusicBotManager.h"
#include "../client/music/MusicClient.h" #include "../client/music/MusicClient.h"
#include "../client/voice/VoiceClient.h" #include "../client/voice/VoiceClient.h"
#include "./ConnectedClient.h"
using namespace ts; using namespace ts;
using namespace ts::server; using namespace ts::server;

View File

@ -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) { void QueryClient::handle_event_read(int fd, short, void *ptr_client) {
static const size_t kReadBufferLength = 1024 * 8;
uint8_t buffer[kReadBufferLength]; uint8_t buffer[kReadBufferLength];
auto client = (QueryClient*) ptr_client; 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); auto length = read(fd, buffer, kReadBufferLength);
if(length <= 0) { if(length <= 0) {
/* error handling */ /* error handling */
if(length == -1 && errno == EAGAIN) { if(length < 0 && errno == EAGAIN) {
/* Nothing to read */ /* Nothing to read */
return; return;
} }

View File

@ -322,9 +322,15 @@ bool PacketEncoder::pop_write_buffer(protocol::OutgoingServerPacket *&result) {
void PacketEncoder::reenqueue_failed_buffer(protocol::OutgoingServerPacket *packet) { void PacketEncoder::reenqueue_failed_buffer(protocol::OutgoingServerPacket *packet) {
std::lock_guard wlock{this->write_queue_mutex}; 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) { if(!this->send_queue_head) {
this->send_queue_tail = &packet->next; this->send_queue_tail = &packet->next;
} }
packet->next = this->send_queue_head; packet->next = this->send_queue_head;
this->send_queue_head = packet; this->send_queue_head = packet;
} }

View File

@ -62,17 +62,17 @@ void WebClient::handleMessageWrite(int fd, short, void *ptr_client) {
event_add(client->writeEvent, nullptr); 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) { void WebClient::handleMessageRead(int fd, short, void *ptr_client) {
auto client = dynamic_pointer_cast<WebClient>(((WebClient*) ptr_client)->ref()); auto client = dynamic_pointer_cast<WebClient>(((WebClient*) ptr_client)->ref());
assert(client); assert(client);
size_t buffer_length = 1024 * 4; uint8_t buffer[kReadBufferSize];
uint8_t buffer[buffer_length]; auto length = recv(fd, buffer, kReadBufferSize, MSG_NOSIGNAL | MSG_DONTWAIT);
auto length = recv(fd, buffer, buffer_length, MSG_NOSIGNAL | MSG_DONTWAIT);
if(length <= 0) { if(length <= 0) {
/* error handling "slow path" */ /* error handling "slow path" */
if(length == 0 && errno == EAGAIN) { if(length < 0 && errno == EAGAIN) {
/* We've currently no data queued */ /* We've currently no data queued */
return; return;
} }