This commit is contained in:
elvis
2022-04-24 01:36:43 +02:00
parent 4fe23200bc
commit 9eaf9cdd49
9 changed files with 163 additions and 82 deletions

View File

@ -107,7 +107,6 @@ int main(int argc, char* argv[]) {
// lista dei comandi
cmd_t *cmds = NULL;
cmds = calloc(1, sizeof(cmd_t));
int opt = 0;
char args[MAXARGLENGTH];
@ -246,7 +245,6 @@ int addCommand(cmd_t **l, char cmd, char *arg) {
strncpy(new->arg, arg, strnlen(arg, MAXARGLENGTH-1)+1);
}
new->next = NULL;
cmd_t *tail = *l;
// se lista vuota aggiungo in cima, altrimenti scorro la lista
if (*l == NULL) {
@ -254,6 +252,7 @@ int addCommand(cmd_t **l, char cmd, char *arg) {
return 0;
}
cmd_t *tail = *l;
while (tail->next) {
tail = tail->next;
}
@ -290,7 +289,7 @@ int execute(cmd_t *l, int print) {
interval.tv_sec = (num/1000);
if (print)
printf("\nt - Tempo fra due richieste: %ld ms\tEsito: ok\n", num);
fprintf(stdout, "t - Tempo fra due richieste: %ld ms\tEsito: ok\n", num);
break;
}
@ -300,6 +299,8 @@ int execute(cmd_t *l, int print) {
tmp = tmp->next;
}
fflush(stdout);
// loop that serches for -f
tmp = l;
while(tmp) {
@ -313,7 +314,7 @@ int execute(cmd_t *l, int print) {
ok = 0;
}
if (print) {
printf("\nf - Connessione al socket: %s\tEsito: ", globalSocket);
fprintf(stdout, "f - Connessione al socket: %s\tEsito: ", globalSocket);
if(ok)
printf("ok\n");
if(!ok)
@ -329,8 +330,11 @@ int execute(cmd_t *l, int print) {
default:
break;
}
tmp = tmp->next;
if(tmp)
tmp = tmp->next;
}
fflush(stdout);
// loop that checks for consistencies:
// 1) -D with no -w or -W after
// 2) -d with no -r or -R after
@ -341,7 +345,7 @@ int execute(cmd_t *l, int print) {
switch (tmp->name) {
case 'D':
if(unmachedD) {
printf("\nError: -D has no -w or -W matching after\n");
fprintf(stdout, "\nError: -D has no -w or -W matching after\n");
return 0;
}
unmachedD = 1;
@ -352,7 +356,7 @@ int execute(cmd_t *l, int print) {
break;
case 'd':
if(unmachedd) {
printf("\nError: -d has no -r or -R matching after\n");
fprintf(stdout, "\nError: -d has no -r or -R matching after\n");
return 0;
}
unmachedd = 1;
@ -367,13 +371,14 @@ int execute(cmd_t *l, int print) {
tmp = tmp->next;
}
if(unmachedD) {
printf("\nError: -D has no -w or -W matching after\n");
fprintf(stdout, "\nError: -D has no -w or -W matching after\n");
return 0;
}
if(unmachedd) {
printf("\nError: -d has no -r or -R matching after\n");
fprintf(stdout, "\nError: -d has no -r or -R matching after\n");
return 0;
}
fflush(stdout);
char *Dir = NULL; // -D folder
char *dir = NULL; // -d folder
@ -509,7 +514,7 @@ int cmd_w(char *dirname, char *Dir, int print) {
}
if (print) {
printf("\nw - Scrivo i seguenti file sul server:");
printf("\nw - Scrivo i seguenti file sul server: ");
fflush(stdout);
}
@ -568,7 +573,7 @@ int cmd_W(char *filelist, char *Dir, int print) {
char *string = tofree;
if (print == 1) {
printf("W - Scrivo i seguenti file sul server:\n");
printf("W - Scrivo i seguenti file sul server: \n");
fflush(stdout);
}

View File

@ -369,6 +369,7 @@ int main(int argc, char *argv[]) {
perror("ERROR FATAL calloc");
goto _cleanup;
}
*connfd = i;
args->connfd = connfd;
args->quit = &quit;
args->request_pipe = request_pipe[1];
@ -396,6 +397,7 @@ int main(int argc, char *argv[]) {
}
}
}
fprintf(stdout, "\n");
destroyThreadPool(pool, 0); // notifico che i thread dovranno uscire
clearWaiting(&waiting); // destroy waiting list

View File

@ -36,7 +36,6 @@ void threadF(void *arg) {
pthread_mutex_t *lock = argl->lock;
waiting_t **waiting = argl->waiting;
fd_set set, tmpset;
FD_ZERO(&set);
FD_SET(connfd, &set);
@ -58,7 +57,6 @@ void threadF(void *arg) {
break; // r!=0 and quit==0
}
// comunicate with the client
msg_t str;
long n;
@ -69,7 +67,7 @@ void threadF(void *arg) {
}
if (n==0)
goto _cleanup;;
goto _cleanup;
str.str = calloc(str.len+1, sizeof(char));
if (!str.str) {
perror("calloc");
@ -84,7 +82,7 @@ void threadF(void *arg) {
}
str.str[str.len] = '\0';
if(strncmp(str.str, "quit", 5)) { // il client vuole chiudere la connessione
if(strncmp(str.str, "quit", 5) == 0) { // il client vuole chiudere la connessione
close(connfd);
int close = -1;
@ -145,7 +143,7 @@ int parser(int len, char *command, queueT *queue, long fd_c, taglia_t* taglia, p
perror("calloc");
return -1;
}
strncpy(string, command, len-1); // strlcpy is only bsd :(
strncpy(string, command, len);
char *token = NULL;
char *token2 = NULL;