serverShutdown.c
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#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/appConfig.h"
#include "include/server.h"
#include "include/monitor.h"
void
serverClose(tVirtualItemServer * server)
{
int i;
for (i=3; i<=server->maxFd; i++) {
if (FD_ISSET(i, &(server->socks))) {
if (i == server->servSock) {
close(server->servSock);
} else {
close(((server->clients)[i]).socket);
free(((server->clients)[i]).buffer);
FD_CLR(i, &(server->socks));
}
}
}
if (NULL != server->wHandle) {
fclose(server->wHandle);
}
}
void
serverShutdown(tVirtualItemServer * 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 {
writeBuffer(&(server->clients[i]), server->wHandle);
clientClose(&((server->clients)[i]));
FD_CLR(i, &(server->socks));
}
}
}
if (NULL != server->wHandle) {
fclose(server->wHandle);
}
}