Close client if connection breaks.

* source/client/receiving-thread.c (receivingThreadHandler): Exit the process if the connection to the server breaks.
* source/server/main.c (main): Minor formatting tweak.
This commit is contained in:
Barra Ó Catháin 2024-03-19 23:28:12 +00:00
parent 0a2d03fdaa
commit 6fc2e4d2b9
2 changed files with 8 additions and 1 deletions

View File

@ -34,10 +34,16 @@ void * receivingThreadHandler(void * threadArguments)
wattrset(gameWindow, A_NORMAL);
struct ServerToClientMessage currentMessage;
int returnValue = 0;
while (true)
{
gnutls_record_recv(session, &currentMessage, sizeof(struct ServerToClientMessage));
returnValue = gnutls_record_recv(session, &currentMessage, sizeof(struct ServerToClientMessage));
if (gnutls_error_is_fatal(returnValue))
{
exit(EXIT_SUCCESS);
}
switch (currentMessage.type)
{
case SYSTEM:

View File

@ -231,6 +231,7 @@ int main (int argc, char ** argv)
gnutls_credentials_set(*tlsSession, GNUTLS_CRD_ANON, serverKey);
gnutls_handshake_set_timeout(*tlsSession, GNUTLS_DEFAULT_HANDSHAKE_TIMEOUT);
gnutls_handshake_set_post_client_hello_function(*tlsSession, checkRequestedHostname);
// Accept the connection:
int newSocket = accept(masterSocket, NULL, NULL);
gnutls_transport_set_int(*tlsSession, newSocket);