Added server status
This commit is contained in:
@ -6,14 +6,15 @@
|
||||
|
||||
#include <conn.h>
|
||||
#include <message.h>
|
||||
#include <serverStatus.h>
|
||||
|
||||
// converte tutti i carattere minuscoli in maiuscoli
|
||||
static void toup(char *str) {
|
||||
char *p = str;
|
||||
while(*p != '\0') {
|
||||
*p = (islower(*p)?toupper(*p):*p);
|
||||
while(*p != '\0') {
|
||||
*p = (islower(*p)?toupper(*p):*p);
|
||||
++p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// funzione eseguita dal Worker thread del pool
|
||||
@ -21,41 +22,46 @@ static void toup(char *str) {
|
||||
//
|
||||
void threadF(void *arg) {
|
||||
assert(arg);
|
||||
long* args = (long*)arg;
|
||||
long connfd = args[0];
|
||||
long* termina = (long*)(args[1]);
|
||||
free(arg);
|
||||
|
||||
long* connfd = (long*)arg[0];
|
||||
serverStatus* status = (serverStatus*)(arg[1]);
|
||||
|
||||
fd_set set, tmpset;
|
||||
FD_ZERO(&set);
|
||||
FD_SET(connfd, &set);
|
||||
|
||||
FD_SET(*connfd, &set);
|
||||
|
||||
do {
|
||||
tmpset=set;
|
||||
int r;
|
||||
// ogni tanto controllo se devo terminare
|
||||
struct timeval timeout={0, 100000}; // 100 milliseconds
|
||||
if ((r=select(connfd+1, &tmpset, NULL, NULL, &timeout)) < 0) {
|
||||
perror("select");
|
||||
perror("Select");
|
||||
break;
|
||||
}
|
||||
if (r==0) {
|
||||
if (*termina) break;
|
||||
if ((status->exiting) != 0)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// comunicate with the client
|
||||
msg_t str;
|
||||
int n;
|
||||
if ((n=readn(connfd, &str.len, sizeof(int))) == -1) {
|
||||
long n;
|
||||
if ((n=readn(connfd, &str.len, sizeof(long))) == -1) {
|
||||
perror("read1");
|
||||
break;
|
||||
}
|
||||
|
||||
if (n==0) break;
|
||||
str.str = calloc((str.len), sizeof(char));
|
||||
|
||||
if (n==0)
|
||||
break;
|
||||
str.str = calloc(str.len, sizeof(char));
|
||||
if (!str.str) {
|
||||
perror("calloc");
|
||||
fprintf(stderr, "Memoria esaurita....\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((n=readn(connfd, str.str, str.len * sizeof(char))) == -1) {
|
||||
perror("read2");
|
||||
free(str.str);
|
||||
@ -75,6 +81,6 @@ void threadF(void *arg) {
|
||||
break;
|
||||
}
|
||||
free(str.str);
|
||||
} while(*termina == 0);
|
||||
close(connfd);
|
||||
} while(status->exiting == 0);
|
||||
close(connfd);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user