mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-01-25 23:47:56 -05:00
Update NetworkClient to use log manager and use common name constant in server logs
This commit is contained in:
@@ -43,6 +43,11 @@ const char yes = 1;
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| NetworkServer name for log entries |
|
||||
\*---------------------------------------------------------*/
|
||||
const char* NETWORKSERVER = "NetworkServer";
|
||||
|
||||
NetworkClientInfo::NetworkClientInfo()
|
||||
{
|
||||
client_string = "Client";
|
||||
@@ -56,7 +61,7 @@ NetworkClientInfo::~NetworkClientInfo()
|
||||
{
|
||||
if(client_sock != INVALID_SOCKET)
|
||||
{
|
||||
LOG_INFO("[NetworkServer] Closing server connection: %s", client_ip.c_str());
|
||||
LOG_INFO("[%s] Closing server connection: %s", NETWORKSERVER, client_ip.c_str());
|
||||
delete client_listen_thread;
|
||||
shutdown(client_sock, SD_RECEIVE);
|
||||
closesocket(client_sock);
|
||||
@@ -304,7 +309,7 @@ void NetworkServer::StartServer()
|
||||
|
||||
if(err)
|
||||
{
|
||||
LOG_ERROR("[NetworkServer] Unable to get address.");
|
||||
LOG_ERROR("[%s] Unable to get address.", NETWORKSERVER);
|
||||
WSACleanup();
|
||||
return;
|
||||
}
|
||||
@@ -318,7 +323,7 @@ void NetworkServer::StartServer()
|
||||
|
||||
if(server_sock[socket_count] == INVALID_SOCKET)
|
||||
{
|
||||
LOG_ERROR("[NetworkServer] Network socket could not be created.");
|
||||
LOG_ERROR("[%s] Network socket could not be created.", NETWORKSERVER);
|
||||
WSACleanup();
|
||||
return;
|
||||
}
|
||||
@@ -335,23 +340,23 @@ void NetworkServer::StartServer()
|
||||
{
|
||||
if(errno == EADDRINUSE)
|
||||
{
|
||||
LOG_ERROR("[NetworkServer] Could not bind network socket. Is port %hu already being used?", GetPort());
|
||||
LOG_ERROR("[%s] Could not bind network socket. Is port %hu already being used?", NETWORKSERVER, GetPort());
|
||||
}
|
||||
else if(errno == EACCES)
|
||||
{
|
||||
LOG_ERROR("[NetworkServer] Could not bind network socket. Access to socket was denied.");
|
||||
LOG_ERROR("[%s] Could not bind network socket. Access to socket was denied.", NETWORKSERVER);
|
||||
}
|
||||
else if(errno == EBADF)
|
||||
{
|
||||
LOG_ERROR("[NetworkServer] Could not bind network socket. sockfd is not a valid file descriptor.");
|
||||
LOG_ERROR("[%s] Could not bind network socket. sockfd is not a valid file descriptor.", NETWORKSERVER);
|
||||
}
|
||||
else if(errno == EINVAL)
|
||||
{
|
||||
LOG_ERROR("[NetworkServer] Could not bind network socket. The socket is already bound to an address, or addrlen is wrong, or addr is not a valid address for this socket's domain.");
|
||||
LOG_ERROR("[%s] Could not bind network socket. The socket is already bound to an address, or addrlen is wrong, or addr is not a valid address for this socket's domain.", NETWORKSERVER);
|
||||
}
|
||||
else if(errno == ENOTSOCK)
|
||||
{
|
||||
LOG_ERROR("[NetworkServer] Could not bind network socket. The file descriptor sockfd does not refer to a socket.");
|
||||
LOG_ERROR("[%s] Could not bind network socket. The file descriptor sockfd does not refer to a socket.", NETWORKSERVER);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -359,7 +364,7 @@ void NetworkServer::StartServer()
|
||||
| errno could be a Linux specific error, see: |
|
||||
| https://man7.org/linux/man-pages/man2/bind.2.html |
|
||||
\*---------------------------------------------------------*/
|
||||
LOG_ERROR("[NetworkServer] Could not bind network socket. Error code: %d.", errno);
|
||||
LOG_ERROR("[%s] Could not bind network socket. Error code: %d.", NETWORKSERVER, errno);
|
||||
}
|
||||
|
||||
WSACleanup();
|
||||
@@ -705,7 +710,7 @@ void NetworkServer::ConnectionThreadFunction(int socket_idx)
|
||||
/*-----------------------------------------------------*\
|
||||
| This thread handles client connections |
|
||||
\*-----------------------------------------------------*/
|
||||
LOG_INFO("[NetworkServer] Network connection thread started on port %hu", GetPort());
|
||||
LOG_INFO("[%s] Network connection thread started on port %hu", NETWORKSERVER, GetPort());
|
||||
|
||||
while(server_online == true)
|
||||
{
|
||||
@@ -721,7 +726,7 @@ void NetworkServer::ConnectionThreadFunction(int socket_idx)
|
||||
\*---------------------------------------------------------*/
|
||||
if(listen(server_sock[socket_idx], 10) < 0)
|
||||
{
|
||||
LOG_INFO("[NetworkServer] Connection thread closed");
|
||||
LOG_INFO("[%s] Connection thread closed", NETWORKSERVER);
|
||||
server_online = false;
|
||||
|
||||
return;
|
||||
@@ -737,7 +742,7 @@ void NetworkServer::ConnectionThreadFunction(int socket_idx)
|
||||
|
||||
if(client_info->client_sock < 0)
|
||||
{
|
||||
LOG_INFO("[NetworkServer] Connection thread closed");
|
||||
LOG_INFO("[%s] Connection thread closed", NETWORKSERVER);
|
||||
server_online = false;
|
||||
|
||||
server_listening = false;
|
||||
@@ -796,7 +801,7 @@ void NetworkServer::ConnectionThreadFunction(int socket_idx)
|
||||
SignalClientInfoChanged();
|
||||
}
|
||||
|
||||
LOG_INFO("[NetworkServer] Connection thread closed");
|
||||
LOG_INFO("[%s] Connection thread closed", NETWORKSERVER);
|
||||
server_online = false;
|
||||
server_listening = false;
|
||||
SignalServerListeningChanged();
|
||||
@@ -865,7 +870,7 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
|
||||
{
|
||||
SOCKET client_sock = client_info->client_sock;
|
||||
|
||||
LOG_INFO("[NetworkServer] Network server started");
|
||||
LOG_INFO("[%s] Network server started", NETWORKSERVER);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| This thread handles messages received from clients |
|
||||
@@ -886,7 +891,7 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
|
||||
|
||||
if(bytes_read <= 0)
|
||||
{
|
||||
LOG_ERROR("[NetworkServer] recv_select failed receiving magic, closing listener");
|
||||
LOG_ERROR("[%s] recv_select failed receiving magic, closing listener", NETWORKSERVER);
|
||||
goto listen_done;
|
||||
}
|
||||
|
||||
@@ -895,7 +900,7 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
|
||||
\*---------------------------------------------*/
|
||||
if(header.pkt_magic[i] != openrgb_sdk_magic[i])
|
||||
{
|
||||
LOG_ERROR("[NetworkServer] Invalid magic received");
|
||||
LOG_ERROR("[%s] Invalid magic received", NETWORKSERVER);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -915,7 +920,7 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
|
||||
|
||||
if(tmp_bytes_read <= 0)
|
||||
{
|
||||
LOG_ERROR("[NetworkServer] recv_select failed receiving header, closing listener");
|
||||
LOG_ERROR("[%s] recv_select failed receiving header, closing listener", NETWORKSERVER);
|
||||
goto listen_done;
|
||||
}
|
||||
|
||||
@@ -937,7 +942,7 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
|
||||
|
||||
if(tmp_bytes_read <= 0)
|
||||
{
|
||||
LOG_ERROR("[NetworkServer] recv_select failed receiving data, closing listener");
|
||||
LOG_ERROR("[%s] recv_select failed receiving data, closing listener", NETWORKSERVER);
|
||||
goto listen_done;
|
||||
}
|
||||
bytes_read += tmp_bytes_read;
|
||||
@@ -1201,7 +1206,7 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("[NetworkServer] ResizeZone packet has invalid size. Packet size: %d", header.pkt_size);
|
||||
LOG_ERROR("[%s] ResizeZone packet has invalid size. Packet size: %d", header.pkt_size, NETWORKSERVER);
|
||||
goto listen_done;
|
||||
}
|
||||
break;
|
||||
@@ -1282,7 +1287,7 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("[NetworkServer] RGBController packet with ID %d has invalid size. Packet size: %d,", header.pkt_id, header.pkt_size);
|
||||
LOG_ERROR("[%s] RGBController packet with ID %d has invalid size. Packet size: %d,", header.pkt_id, header.pkt_size, NETWORKSERVER);
|
||||
goto listen_done;
|
||||
}
|
||||
break;
|
||||
@@ -1300,7 +1305,7 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("[NetworkServer] UpdateSingleLED packet has invalid size. Packet size: %d", header.pkt_size);
|
||||
LOG_ERROR("[%s] UpdateSingleLED packet has invalid size. Packet size: %d", header.pkt_size, NETWORKSERVER);
|
||||
goto listen_done;
|
||||
}
|
||||
break;
|
||||
@@ -1320,7 +1325,7 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("[NetworkServer] ClearSegments packet has invalid size. Packet size: %d", header.pkt_size);
|
||||
LOG_ERROR("[%s] ClearSegments packet has invalid size. Packet size: %d", header.pkt_size, NETWORKSERVER);
|
||||
goto listen_done;
|
||||
}
|
||||
break;
|
||||
@@ -1339,7 +1344,7 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("[NetworkServer] AddSegment packet has invalid size. Packet size: %d", header.pkt_size);
|
||||
LOG_ERROR("[%s] AddSegment packet has invalid size. Packet size: %d", header.pkt_size, NETWORKSERVER);
|
||||
goto listen_done;
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user