Tiny fixups (server conn info leak closed, log va leak closed, config dir optimized)
Commit amended for code style by Adam Honse <calcprogrammer1@gmail.com>
This commit is contained in:
parent
33b840b2b9
commit
abfb6ea22d
5 changed files with 34 additions and 11 deletions
|
|
@ -186,8 +186,9 @@ void LogManager::_append(const char* filename, int line, unsigned int level, con
|
||||||
va_list va2;
|
va_list va2;
|
||||||
va_copy(va2, va);
|
va_copy(va2, va);
|
||||||
int len = vsnprintf(nullptr, 0, fmt, va);
|
int len = vsnprintf(nullptr, 0, fmt, va);
|
||||||
mes->buffer.resize(len + 1);
|
mes->buffer.resize(len);
|
||||||
vsnprintf(&(mes->buffer[0]), len + 1, fmt, va2);
|
vsnprintf(&(mes->buffer[0]), len + 1, fmt, va2);
|
||||||
|
va_end(va2);
|
||||||
|
|
||||||
/*-------------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
| Fill in message information |
|
| Fill in message information |
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
\*-----------------------------------------*/
|
\*-----------------------------------------*/
|
||||||
|
|
||||||
#include "NetworkServer.h"
|
#include "NetworkServer.h"
|
||||||
|
#include "ResourceManager.h"
|
||||||
|
#include "LogManager.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
|
|
@ -33,6 +35,17 @@ const char yes = 1;
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
|
|
||||||
|
NetworkClientInfo::~NetworkClientInfo()
|
||||||
|
{
|
||||||
|
if(client_sock != INVALID_SOCKET)
|
||||||
|
{
|
||||||
|
LOG_NOTICE("Closing server connection: %s", client_ip);
|
||||||
|
delete client_listen_thread;
|
||||||
|
shutdown(client_sock, SD_RECEIVE);
|
||||||
|
closesocket(client_sock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NetworkServer::NetworkServer(std::vector<RGBController *>& control) : controllers(control)
|
NetworkServer::NetworkServer(std::vector<RGBController *>& control) : controllers(control)
|
||||||
{
|
{
|
||||||
port_num = OPENRGB_SDK_PORT;
|
port_num = OPENRGB_SDK_PORT;
|
||||||
|
|
@ -280,17 +293,17 @@ void NetworkServer::StopServer()
|
||||||
server_online = false;
|
server_online = false;
|
||||||
|
|
||||||
ServerClientsMutex.lock();
|
ServerClientsMutex.lock();
|
||||||
|
|
||||||
for(unsigned int client_idx = 0; client_idx < ServerClients.size(); client_idx++)
|
for(unsigned int client_idx = 0; client_idx < ServerClients.size(); client_idx++)
|
||||||
{
|
{
|
||||||
shutdown(ServerClients[client_idx]->client_sock, SD_RECEIVE);
|
|
||||||
closesocket(ServerClients[client_idx]->client_sock);
|
|
||||||
delete ServerClients[client_idx];
|
delete ServerClients[client_idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ServerClients.clear();
|
||||||
|
|
||||||
shutdown(server_sock, SD_RECEIVE);
|
shutdown(server_sock, SD_RECEIVE);
|
||||||
closesocket(server_sock);
|
closesocket(server_sock);
|
||||||
|
|
||||||
ServerClients.clear();
|
|
||||||
ServerClientsMutex.unlock();
|
ServerClientsMutex.unlock();
|
||||||
|
|
||||||
if(ConnectionThread)
|
if(ConnectionThread)
|
||||||
|
|
@ -726,9 +739,6 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
|
||||||
}
|
}
|
||||||
|
|
||||||
listen_done:
|
listen_done:
|
||||||
printf("Server connection closed\r\n");
|
|
||||||
shutdown(client_info->client_sock, SD_RECEIVE);
|
|
||||||
closesocket(client_info->client_sock);
|
|
||||||
|
|
||||||
ServerClientsMutex.lock();
|
ServerClientsMutex.lock();
|
||||||
|
|
||||||
|
|
@ -736,13 +746,14 @@ listen_done:
|
||||||
{
|
{
|
||||||
if(ServerClients[this_idx] == client_info)
|
if(ServerClients[this_idx] == client_info)
|
||||||
{
|
{
|
||||||
delete client_info->client_listen_thread;
|
|
||||||
delete client_info;
|
delete client_info;
|
||||||
ServerClients.erase(ServerClients.begin() + this_idx);
|
ServerClients.erase(ServerClients.begin() + this_idx);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
client_info = nullptr;
|
||||||
|
|
||||||
ServerClientsMutex.unlock();
|
ServerClientsMutex.unlock();
|
||||||
|
|
||||||
/*-------------------------------------------------*\
|
/*-------------------------------------------------*\
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,11 @@
|
||||||
|
|
||||||
typedef void (*NetServerCallback)(void *);
|
typedef void (*NetServerCallback)(void *);
|
||||||
|
|
||||||
struct NetworkClientInfo
|
class NetworkClientInfo
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
~NetworkClientInfo();
|
||||||
|
|
||||||
SOCKET client_sock;
|
SOCKET client_sock;
|
||||||
std::thread * client_listen_thread;
|
std::thread * client_listen_thread;
|
||||||
std::string client_string;
|
std::string client_string;
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,8 @@ ResourceManager::ResourceManager()
|
||||||
detection_is_required = false;
|
detection_is_required = false;
|
||||||
DetectDevicesThread = nullptr;
|
DetectDevicesThread = nullptr;
|
||||||
|
|
||||||
|
SetupConfigurationDirectory();
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
| Load settings from file |
|
| Load settings from file |
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
|
|
@ -309,9 +311,9 @@ void ResourceManager::I2CBusListChanged()
|
||||||
I2CBusListChangeMutex.unlock();
|
I2CBusListChangeMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ResourceManager::GetConfigurationDirectory()
|
void ResourceManager::SetupConfigurationDirectory()
|
||||||
{
|
{
|
||||||
std::string config_dir = "";
|
config_dir.clear();
|
||||||
const char* xdg_config_home = getenv("XDG_CONFIG_HOME");
|
const char* xdg_config_home = getenv("XDG_CONFIG_HOME");
|
||||||
const char* home = getenv("HOME");
|
const char* home = getenv("HOME");
|
||||||
const char* appdata = getenv("APPDATA");
|
const char* appdata = getenv("APPDATA");
|
||||||
|
|
@ -357,7 +359,10 @@ std::string ResourceManager::GetConfigurationDirectory()
|
||||||
{
|
{
|
||||||
config_dir = "./";
|
config_dir = "./";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ResourceManager::GetConfigurationDirectory()
|
||||||
|
{
|
||||||
return(config_dir);
|
return(config_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void DetectDevicesThreadFunction();
|
void DetectDevicesThreadFunction();
|
||||||
void UpdateDetectorSettings();
|
void UpdateDetectorSettings();
|
||||||
|
void SetupConfigurationDirectory();
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------------------*\
|
||||||
| Static pointer to shared instance of ResourceManager |
|
| Static pointer to shared instance of ResourceManager |
|
||||||
|
|
@ -243,4 +244,6 @@ private:
|
||||||
std::mutex I2CBusListChangeMutex;
|
std::mutex I2CBusListChangeMutex;
|
||||||
std::vector<I2CBusListChangeCallback> I2CBusListChangeCallbacks;
|
std::vector<I2CBusListChangeCallback> I2CBusListChangeCallbacks;
|
||||||
std::vector<void *> I2CBusListChangeCallbackArgs;
|
std::vector<void *> I2CBusListChangeCallbackArgs;
|
||||||
|
|
||||||
|
std::string config_dir;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue