serverShutdown.c
1 KB
#include <stdio.h> /* for printf() and fprintf() */
#include <sys/select.h> /* for select system call and related */
#include <sys/socket.h> /* for select system call and related */
#include <stdlib.h> /* for exit */
#include <string.h> /* for memset and stuff */
#include <unistd.h> /* for getopt */
#include <errno.h> /* for errno */
#include "../include/server.h"
#include "../include/monitor.h"
#include "../include/writeBuffer.h"
void
serverShutdown(tServer * server)
{
int i;
for (i=3; i<=server->maxFd; i++) {
if (FD_ISSET(i, &(server->socks))) {
if (i == server->servSock) {
shutdown(server->servSock, SHUT_RDWR);
close(server->servSock);
} else {
/* actual do nothing except closing the client */
clientClose(&((server->clients)[i]));
FD_CLR(i, &(server->socks));
}
}
}
if (NULL != server->wHandle) {
fclose(server->wHandle);
}
}