Fix a segfault that happens when a client fails a handshake.
This commit is contained in:
parent
b3ef4c1bb9
commit
c032aa7dad
|
@ -40,7 +40,7 @@ int main(int argc, char ** argv)
|
||||||
time_t currentTime;
|
time_t currentTime;
|
||||||
unsigned delay = 800;
|
unsigned delay = 800;
|
||||||
int socketFileDesc, connectionFileDesc, length, clientsAmount,
|
int socketFileDesc, connectionFileDesc, length, clientsAmount,
|
||||||
socketCheck, activityCheck, returnVal;
|
socketCheck, activityCheck;
|
||||||
fd_set connectedClients;
|
fd_set connectedClients;
|
||||||
pthread_t gameLogicThread, outputThread, schemeThread;
|
pthread_t gameLogicThread, outputThread, schemeThread;
|
||||||
int clientSockets[PLAYERCOUNT];
|
int clientSockets[PLAYERCOUNT];
|
||||||
|
@ -281,18 +281,21 @@ int main(int argc, char ** argv)
|
||||||
// See if we can put in the client:
|
// See if we can put in the client:
|
||||||
for (int index = 0; index < PLAYERCOUNT; index++)
|
for (int index = 0; index < PLAYERCOUNT; index++)
|
||||||
{
|
{
|
||||||
|
printf("Checking for slot: %d\n", index);
|
||||||
// When there is an empty slot, pop it in:
|
// When there is an empty slot, pop it in:
|
||||||
if (clientSockets[index] == 0)
|
if (clientSockets[index] == 0)
|
||||||
{
|
{
|
||||||
|
volatile int handshakeReturnValue = 0;
|
||||||
clientSockets[index] = connectionFileDesc;
|
clientSockets[index] = connectionFileDesc;
|
||||||
//printf("Adding to list of sockets as %d.\n", index);
|
|
||||||
gnutls_transport_set_int(tlssessions[index], clientSockets[index]);
|
gnutls_transport_set_int(tlssessions[index], clientSockets[index]);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
returnVal = gnutls_handshake(tlssessions[index]);
|
handshakeReturnValue = gnutls_handshake(tlssessions[index]);
|
||||||
}
|
} while (handshakeReturnValue < 0 && gnutls_error_is_fatal(handshakeReturnValue) == 0);
|
||||||
while (returnVal < 0 && gnutls_error_is_fatal(returnVal) == 0);
|
|
||||||
|
|
||||||
|
// If it's good, send them the welcome message:
|
||||||
|
if(handshakeReturnValue == 0)
|
||||||
|
{
|
||||||
// Send a greeting message:
|
// Send a greeting message:
|
||||||
memcpy(sendBuffer.senderName, "\0 Login > \0", 11);
|
memcpy(sendBuffer.senderName, "\0 Login > \0", 11);
|
||||||
strcpy(sendBuffer.messageContent, "Welcome to the server!");
|
strcpy(sendBuffer.messageContent, "Welcome to the server!");
|
||||||
|
@ -311,6 +314,13 @@ int main(int argc, char ** argv)
|
||||||
pushQueue(inputQueue, newMessage, INPUT_MESSAGE);
|
pushQueue(inputQueue, newMessage, INPUT_MESSAGE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If it's not good, close it, we don't want it:
|
||||||
|
shutdown(clientSockets[index], 2);
|
||||||
|
close(clientSockets[index]);
|
||||||
|
clientSockets[index] = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Otherwise, it's a client we need to interact with:
|
// Otherwise, it's a client we need to interact with:
|
||||||
|
|
Loading…
Reference in New Issue