From cbfd27b95489b812a78a9caad7da79814aecee3a Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 26 Apr 2020 11:29:20 +0200 Subject: [PATCH] Fixed the broken pipe issue --- license/server/LicenseServer.cpp | 20 +++++++++++++------ license/server/LicenseServer.h | 2 +- license/server/WebAPI.h | 1 - .../client/voice/VoiceClientConnection.cpp | 2 +- shared | 2 +- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/license/server/LicenseServer.cpp b/license/server/LicenseServer.cpp index fef87f8..b126a23 100644 --- a/license/server/LicenseServer.cpp +++ b/license/server/LicenseServer.cpp @@ -144,6 +144,8 @@ void LicenseServer::handleEventWrite(int fd, short, void* ptrServer) { if(writtenBytes == -1 && errno == EAGAIN) return; logError(LOG_LICENSE_CONTROLL, "Invalid write. Disconnecting remote client. Message: {}/{}", errno, strerror(errno)); + server->unregisterClient(client); + return; } else { write_buffer->index += writtenBytes; } @@ -187,7 +189,7 @@ void ConnectedClient::init() { TAILQ_INIT(&network.write_queue); } -void ConnectedClient::uninit() { +void ConnectedClient::uninit(bool blocking) { { lock_guard queue_lock{this->network.write_queue_lock}; ts::buffer::RawBuffer* buffer; @@ -201,11 +203,17 @@ void ConnectedClient::uninit() { close(this->network.fileDescriptor); network.fileDescriptor = 0; } - if(this->network.readEvent) event_del(this->network.readEvent); - this->network.readEvent = nullptr; - if(this->network.writeEvent) event_del(this->network.writeEvent); - this->network.writeEvent = nullptr; + auto read_event = std::exchange(this->network.readEvent, nullptr); + auto write_event = std::exchange(this->network.writeEvent, nullptr); + + if(blocking) { + if(read_event) event_del_block(read_event); + if(write_event) event_del_block(write_event); + } else { + if(read_event) event_del_noblock(read_event); + if(write_event) event_del_noblock(write_event); + } } void LicenseServer::handleEventRead(int fd, short, void* ptrServer) { @@ -312,7 +320,7 @@ void LicenseServer::unregisterClient(const std::shared_ptr &cli std::lock_guard state_lock{client->protocol.state_lock}; client->protocol.state = protocol::UNCONNECTED; } - client->uninit(); + client->uninit(this_thread::get_id() != this->event_base_dispatch.get_id()); } void LicenseServer::cleanup_clients() { diff --git a/license/server/LicenseServer.h b/license/server/LicenseServer.h index 55a8969..0d73adc 100644 --- a/license/server/LicenseServer.h +++ b/license/server/LicenseServer.h @@ -57,7 +57,7 @@ namespace license { bool invalid_license = false; void init(); - void uninit(); + void uninit(bool /* blocking */); void sendPacket(const protocol::packet&); inline std::string address() { return inet_ntoa(network.remoteAddr.sin_addr); } diff --git a/license/server/WebAPI.h b/license/server/WebAPI.h index 78e476e..ef17712 100644 --- a/license/server/WebAPI.h +++ b/license/server/WebAPI.h @@ -92,7 +92,6 @@ namespace license { std::deque> clients; threads::ThreadPool scheduler{1, "WebStatistics #"}; - protected: static void handleEventAccept(int, short, void*); static void handleEventRead(int, short, void*); diff --git a/server/src/client/voice/VoiceClientConnection.cpp b/server/src/client/voice/VoiceClientConnection.cpp index af163db..4f65b05 100644 --- a/server/src/client/voice/VoiceClientConnection.cpp +++ b/server/src/client/voice/VoiceClientConnection.cpp @@ -673,7 +673,7 @@ void VoiceClientConnection::send_command(const std::string_view &command, bool l } /* we don't need to make the command longer than it is */ - if(compressed_size < command.length() || this->client->getType() == ClientType::CLIENT_TEAMSPEAK) { /* TS3 requires each splituped packet to be compressed */ + if(compressed_size < command.length() || this->client->getType() == ClientType::CLIENT_TEAMSPEAK) { /* TS3 requires each splituped packet to be compressed (Update: Not 100% sure since there was another bug when discovering this but I've kept it since) */ own_data_buffer = true; data_buffer = (char*) compressed_buffer; own_data_buffer_ptr = compressed_buffer; diff --git a/shared b/shared index 5842bbe..bcbff04 160000 --- a/shared +++ b/shared @@ -1 +1 @@ -Subproject commit 5842bbe0676cb06c3947943fb5dd422aff0bef16 +Subproject commit bcbff04979d29d3a5a59cf0fa6daa35324bcf46c