Process received magic using a loop in client and server

This commit is contained in:
Adam Honse 2024-03-25 19:56:33 -05:00
parent cf4fd16b09
commit 89983dcdd1
2 changed files with 32 additions and 134 deletions

View file

@ -403,76 +403,25 @@ void NetworkClient::ListenThreadFunction()
int bytes_read = 0; int bytes_read = 0;
char * data = NULL; char * data = NULL;
/*---------------------------------------------------------*\ for(unsigned int i = 0; i < 4; i++)
| Read first byte of magic |
\*---------------------------------------------------------*/
bytes_read = recv_select(client_sock, &header.pkt_magic[0], 1, 0);
if(bytes_read <= 0)
{ {
goto listen_done; /*---------------------------------------------------------*\
} | Read byte of magic |
\*---------------------------------------------------------*/
bytes_read = recv_select(client_sock, &header.pkt_magic[i], 1, 0);
/*---------------------------------------------------------*\ if(bytes_read <= 0)
| Test first character of magic - 'O' | {
\*---------------------------------------------------------*/ goto listen_done;
if(header.pkt_magic[0] != 'O') }
{
continue;
}
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Read second byte of magic | | Test characters of magic "ORGB" |
\*---------------------------------------------------------*/ \*---------------------------------------------------------*/
bytes_read = recv_select(client_sock, &header.pkt_magic[1], 1, 0); if(header.pkt_magic[i] != openrgb_sdk_magic[i])
{
if(bytes_read <= 0) continue;
{ }
goto listen_done;
}
/*---------------------------------------------------------*\
| Test second character of magic - 'R' |
\*---------------------------------------------------------*/
if(header.pkt_magic[1] != 'R')
{
continue;
}
/*---------------------------------------------------------*\
| Read third byte of magic |
\*---------------------------------------------------------*/
bytes_read = recv_select(client_sock, &header.pkt_magic[2], 1, 0);
if(bytes_read <= 0)
{
goto listen_done;
}
/*---------------------------------------------------------*\
| Test third character of magic - 'G' |
\*---------------------------------------------------------*/
if(header.pkt_magic[2] != 'G')
{
continue;
}
/*---------------------------------------------------------*\
| Read fourth byte of magic |
\*---------------------------------------------------------*/
bytes_read = recv_select(client_sock, &header.pkt_magic[3], 1, 0);
if(bytes_read <= 0)
{
goto listen_done;
}
/*---------------------------------------------------------*\
| Test fourth character of magic - 'B' |
\*---------------------------------------------------------*/
if(header.pkt_magic[3] != 'B')
{
continue;
} }
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\

View file

@ -552,76 +552,25 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
int bytes_read = 0; int bytes_read = 0;
char * data = NULL; char * data = NULL;
/*---------------------------------------------------------*\ for(unsigned int i = 0; i < 4; i++)
| Read first byte of magic |
\*---------------------------------------------------------*/
bytes_read = recv_select(client_sock, &header.pkt_magic[0], 1, 0);
if(bytes_read <= 0)
{ {
goto listen_done; /*---------------------------------------------------------*\
} | Read byte of magic |
\*---------------------------------------------------------*/
bytes_read = recv_select(client_sock, &header.pkt_magic[i], 1, 0);
/*---------------------------------------------------------*\ if(bytes_read <= 0)
| Test first character of magic - 'O' | {
\*---------------------------------------------------------*/ goto listen_done;
if(header.pkt_magic[0] != 'O') }
{
continue;
}
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\
| Read second byte of magic | | Test characters of magic "ORGB" |
\*---------------------------------------------------------*/ \*---------------------------------------------------------*/
bytes_read = recv_select(client_sock, &header.pkt_magic[1], 1, 0); if(header.pkt_magic[i] != openrgb_sdk_magic[i])
{
if(bytes_read <= 0) continue;
{ }
goto listen_done;
}
/*---------------------------------------------------------*\
| Test second character of magic - 'R' |
\*---------------------------------------------------------*/
if(header.pkt_magic[1] != 'R')
{
continue;
}
/*---------------------------------------------------------*\
| Read third byte of magic |
\*---------------------------------------------------------*/
bytes_read = recv_select(client_sock, &header.pkt_magic[2], 1, 0);
if(bytes_read <= 0)
{
goto listen_done;
}
/*---------------------------------------------------------*\
| Test third character of magic - 'G' |
\*---------------------------------------------------------*/
if(header.pkt_magic[2] != 'G')
{
continue;
}
/*---------------------------------------------------------*\
| Read fourth byte of magic |
\*---------------------------------------------------------*/
bytes_read = recv_select(client_sock, &header.pkt_magic[3], 1, 0);
if(bytes_read <= 0)
{
goto listen_done;
}
/*---------------------------------------------------------*\
| Test fourth character of magic - 'B' |
\*---------------------------------------------------------*/
if(header.pkt_magic[3] != 'B')
{
continue;
} }
/*---------------------------------------------------------*\ /*---------------------------------------------------------*\