client now disconnects

This commit is contained in:
elvis
2022-05-01 00:10:28 +02:00
parent 85231d073f
commit e095f4306f
4 changed files with 55 additions and 16 deletions

View File

@ -309,22 +309,32 @@ int main(int argc, char *argv[]) {
continue;
}
if (i == request_pipe[0]) { // un worker ha finito di servire un client
int pdr; // ottengo il descrittore della pipe
if (readn(request_pipe[0], &pdr, sizeof(int)) == -1) {
long pdr; // ottengo il descrittore della pipe
if (readn(request_pipe[0], &pdr, sizeof(long)) == -1) {
perror("readn");
free(connfd);
break;
}
switch (pdr) {
case -1: // client disconnected
--numberOfConnections;
n = snprintf(buf, sizeof(buf), "Client %ld disconnected.\n", pdr);
if( n<0 ) {
perror("snprintf");
free(connfd);
goto _cleanup;
}
if( taglia_log(taglia, buf) < 0) {
free(connfd);
goto _cleanup;
}
if (stopNewConnections && numberOfConnections <= 0) {
quit = 1;
// termino il signalThread
pthread_cancel(sighandler_thread);
break;
}
free(connfd);
continue;
default: // client served but not disconnected
FD_SET(pdr, &set);
@ -399,7 +409,6 @@ int main(int argc, char *argv[]) {
// aggiungo al threadpool
int r = addToThreadPool(pool, threadF, args);
if (r == 0) {
numberOfConnections++;
free(connfd);
continue; // aggiunto con successo
}