Wait for thread cancel

This commit is contained in:
Ugo Cirmignani
2019-03-27 21:58:29 +01:00
parent 110f2d0163
commit 1822494e95
3 changed files with 30 additions and 5 deletions

View File

@ -497,6 +497,11 @@ int parseCommandPasv(ftpDataType * data, int socketId)
{ {
returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread); returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread);
//printf("\npasv pthread_cancel = %d", returnCode); //printf("\npasv pthread_cancel = %d", returnCode);
do
{
printf("\nQuit command received the Pasv Thread has been cancelled!!!");
usleep(10000);
} while (ftpData->clients[socketId].workerData.threadIsAlive == 1);
} }
if (data->clients[socketId].workerData.threadHasBeenCreated == 1) if (data->clients[socketId].workerData.threadHasBeenCreated == 1)
@ -533,6 +538,11 @@ int parseCommandPort(ftpDataType * data, int socketId)
if (data->clients[socketId].workerData.threadIsAlive == 1) if (data->clients[socketId].workerData.threadIsAlive == 1)
{ {
returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread); returnCode = pthread_cancel(data->clients[socketId].workerData.workerThread);
do
{
printf("\nQuit command received the Pasv Thread has been cancelled!!!");
usleep(10000);
} while (ftpData->clients[socketId].workerData.threadIsAlive == 1);
} }
if (data->clients[socketId].workerData.threadHasBeenCreated == 1) if (data->clients[socketId].workerData.threadHasBeenCreated == 1)
{ {
@ -566,6 +576,11 @@ int parseCommandAbor(ftpDataType * data, int socketId)
if (data->clients[socketId].workerData.threadIsAlive == 1) if (data->clients[socketId].workerData.threadIsAlive == 1)
{ {
pthread_cancel(data->clients[socketId].workerData.workerThread); pthread_cancel(data->clients[socketId].workerData.workerThread);
do
{
printf("\nQuit command received the Pasv Thread has been cancelled!!!");
usleep(10000);
} while (ftpData->clients[socketId].workerData.threadIsAlive == 1);
} }
returnCode = socketPrintf(data, socketId, "s", "426 ABORT\r\n"); returnCode = socketPrintf(data, socketId, "s", "426 ABORT\r\n");

View File

@ -632,10 +632,14 @@ void resetClientData(ftpDataType *data, int clientId, int isInitialization)
{ {
if (isInitialization != 1) if (isInitialization != 1)
{ {
if (data->clients[clientId].workerData.threadIsAlive == 1){ if (data->clients[clientId].workerData.threadIsAlive == 1) {
pthread_cancel(data->clients[clientId].workerData.workerThread); pthread_cancel(data->clients[clientId].workerData.workerThread);
usleep(10000); do
printf("Thread had ben cancelled!"); {
printf("\nQuit command received the Pasv Thread has been cancelled!!!");
usleep(10000);
} while (ftpData->clients[clientId].workerData.threadIsAlive == 1);
} }
pthread_mutex_destroy(&data->clients[clientId].conditionMutex); pthread_mutex_destroy(&data->clients[clientId].conditionMutex);
pthread_cond_destroy(&data->clients[clientId].conditionVariable); pthread_cond_destroy(&data->clients[clientId].conditionVariable);

View File

@ -596,9 +596,15 @@ void closeClient(ftpDataType * ftpData, int processingSocket)
if (ftpData->clients[processingSocket].workerData.threadIsAlive == 1) if (ftpData->clients[processingSocket].workerData.threadIsAlive == 1)
{ {
pthread_cancel(ftpData->clients[processingSocket].workerData.workerThread); pthread_cancel(ftpData->clients[processingSocket].workerData.workerThread);
printf("\nQuit command received the Pasv Thread has been cancelled!!!");
usleep(10000); do
{
printf("\nQuit command received the Pasv Thread has been cancelled!!!");
usleep(10000);
} while (ftpData->clients[processingSocket].workerData.threadIsAlive == 1);
} }
FD_CLR(ftpData->clients[processingSocket].socketDescriptor, &ftpData->connectionData.rsetAll); FD_CLR(ftpData->clients[processingSocket].socketDescriptor, &ftpData->connectionData.rsetAll);