last bug fixes and test2 & test3

This commit is contained in:
elvis
2022-05-03 23:14:39 +02:00
parent 3fb7c1e886
commit 4b7f15c555
13 changed files with 141 additions and 40 deletions

View File

@ -255,15 +255,15 @@ int openFile(const char* pathname, int flags) {
if(strncmp(res->ME, MEFP, sizeof(res->ME)) == 0) {
// some files were purged
if(openedFiles->print){
fprintf(openedFiles->out, "Il server ha espulso i seguenti file:\n");
fprintf(openedFiles->out, "\nIl server ha espulso i seguenti file:\n");
fflush(openedFiles->out);
for(int i=0;i<res->numfiles;++i) {
fprintf(openedFiles->out, "%d) %s\n", i, res->rf[i].path);
fprintf(openedFiles->out, "\t%d) %s\n", i+1, res->rf[i].path);
}
}
if(openedFiles->wDir) {
if(openedFiles->print) {
fprintf(openedFiles->out, "I file espulsi sono stati scritti nella cartella: %s\n", openedFiles->wDir);
fprintf(openedFiles->out, "\tI file espulsi sono stati scritti nella cartella: %s\n", openedFiles->wDir);
fflush(openedFiles->out);
}
if(storeFilesInDirectory(openedFiles->wDir, res->numfiles, res->rf) == -1) {
@ -275,7 +275,7 @@ int openFile(const char* pathname, int flags) {
}
} else {
if(openedFiles->print) {
fprintf(openedFiles->out, "I file espulsi non sono stati memorizzati su disco\n");
fprintf(openedFiles->out, "\tI file espulsi non sono stati memorizzati su disco\n");
fflush(openedFiles->out);
}
}

View File

@ -157,7 +157,8 @@ int taglia_stats(taglia_t *taglia, FILE *stream) {
double res = ((double) taglia->max_size)/((double) 1000000);
fprintf(stream, "Numero di file massimo memorizzato nel server: %zu\n", taglia->max_files);
fprintf(stream, "Dimensione massima in Mbytes raggiunta dal file storage: %.2lf MB\n", res);
// fprintf(stream, "Dimensione massima in Mbytes raggiunta dal file storage: %.2lf MB\n", res);
fprintf(stream, "Dimensione massima in Mbytes raggiunta dal file storage: %lf MB\n", res);
fprintf(stream, "Numero di volte in cui lalgoritmo di rimpiazzamento della cache è stato eseguito per selezionare uno o più file \"vittima\": %zu\n", taglia->cache_misses);
fflush(stream);

View File

@ -339,7 +339,7 @@ void readFile(char *filepath, queueT *q, long fd_c, taglia_t *taglia) {
return;
}
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una readFile sul file \"%s\" e' terminata con successo\n", fd_c, filepath);
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una readFile sul file \"%s\" di dimensione = %ld e' terminata con successo\n", fd_c, filepath, f->valid);
sendMessageFile(MEOK, f, fd_c, taglia, tmp_buf);
destroyFile(f); // f is a copy so we need to cleen up
return;
@ -366,6 +366,7 @@ void readNFiles(int num, queueT *q, long fd_c, taglia_t *taglia){
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una readNFile (n = %d) e' terminata con successo. File inviati:\n", fd_c, num);
// extract n files, we dont check if the client can actually modify
// the files since we add them back immediatly
size_t tot = 0;
for(int i=0;i<ntosend;++i) {
toSend[i] = dequeue(q);
if(!toSend[i]) {
@ -383,8 +384,10 @@ void readNFiles(int num, queueT *q, long fd_c, taglia_t *taglia){
serror(MESE, fd_c, taglia, tmp_buf);
return;
}
n += snprintf(tmp_buf+n, m-n, "\t%d) \"%s\"\n", i, toSend[i]->filepath);
tot += toSend[i]->valid;
n += snprintf(tmp_buf+n, m-n, "\t%d) \"%s\" dim = %ld\n", i, toSend[i]->filepath, toSend[i]->valid);
}
n += snprintf(tmp_buf+n, m-n, "readNFile dimensione totale = %ld\n", tot);
sendMessageFileN(MEOK, toSend, ntosend, fd_c, taglia, tmp_buf);
free(toSend);
@ -434,6 +437,13 @@ void writeFile(char *filepath, size_t size, queueT *q, long fd_c, taglia_t *tagl
}
destroyFile(f); // not needed anymore
if(trueSizeAdded > q->maxSize) { // removing all files would not be enought
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una writeFile (append = %x) sul file \"%s\", dimensione = %ld ma il file e' piu' grande della dimensione massima\n", fd_c, append, filepath, size);
errno = EFBIG;
serror(MENT, fd_c, taglia, tmp_buf);
return;
}
if(trueSizeAdded + getSize(q) > q->maxSize) {
// writing would be more than capacity
fileT **removed = NULL; // array that may (worst case) hold all files to be sent to the client

View File

@ -264,7 +264,7 @@ fileT ** dequeueN(queueT *q, char *filepath, size_t s) {
break; // we eliminated everything so we must have enought space
}
}
returnList = realloc(returnList, purged+1 * sizeof(fileT*));
returnList = realloc(returnList, (purged+1) * sizeof(fileT*));
returnList[purged] = NULL; // null terminated
tmp->data->size += s;