-w, -W, -r all working
This commit is contained in:
@ -1259,7 +1259,6 @@ int reciveData(response_t *res, int expected) {
|
||||
readnres = readn(fd_skt, &res->numfiles, sizeof(int));
|
||||
if(readnres<=0) // readn sets errno
|
||||
return -1;
|
||||
|
||||
if(res->rf)
|
||||
free(res->rf);
|
||||
res->rf = calloc(res->numfiles, sizeof(recivedFile_t));
|
||||
@ -1267,6 +1266,7 @@ int reciveData(response_t *res, int expected) {
|
||||
perror("calloc");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// get files
|
||||
for(int i=0;i<res->numfiles;++i) {
|
||||
// read path
|
||||
@ -1350,10 +1350,11 @@ _nofile:
|
||||
// file purged
|
||||
res->meerrno = 0;
|
||||
// get number of files sent
|
||||
readnres = readn(fd_skt, &res->numfiles, sizeof(int));
|
||||
readnres = readn(fd_skt, &res->numfiles, sizeof(int64_t));
|
||||
if(readnres<=0) // readn sets errno
|
||||
return -1;
|
||||
|
||||
|
||||
if(res->rf)
|
||||
free(res->rf);
|
||||
res->rf = calloc(res->numfiles, sizeof(recivedFile_t));
|
||||
@ -1386,6 +1387,16 @@ _nofile:
|
||||
readnres = readn(fd_skt, &res->rf[i].filelen, sizeof(int64_t));
|
||||
if(readnres<=0) // readn sets errno
|
||||
return -1;
|
||||
|
||||
// file has lenght 0 -> allocate memory but dont read
|
||||
if(res->rf[i].filelen == 0) {
|
||||
res->rf[i].file = calloc(1, sizeof(char));
|
||||
if(!res->rf[i].file){
|
||||
perror("calloc");
|
||||
return -1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
res->rf[i].file = calloc(res->rf[i].filelen, sizeof(char));
|
||||
if(!res->rf[i].file){
|
||||
perror("calloc");
|
||||
|
||||
@ -96,16 +96,18 @@ int sendFile(fileT *f, long fd_c, taglia_t *taglia) {
|
||||
perror("writen");
|
||||
return -1;
|
||||
}
|
||||
if (writen(fd_c, f->data, f->valid) < 0) {
|
||||
perror("writen");
|
||||
return -1;
|
||||
if(validLength != 0) { // if file has length 0 dont write
|
||||
if (writen(fd_c, f->data, validLength) < 0) {
|
||||
perror("writen");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
char tmp_log[LOGBUFSIZE];
|
||||
int n = 0;
|
||||
size_t m = sizeof(tmp_log);
|
||||
|
||||
n += snprintf(tmp_log+n, m-n, "File \"%s\", di dimensione %"PRId64" Bytes al client %ld .\n", f->filepath, validLength, fd_c);
|
||||
n += snprintf(tmp_log+n, m-n, "Inviato file \"%s\", di dimensione %"PRId64" Bytes al client %ld .\n", f->filepath, validLength, fd_c);
|
||||
if(taglia_write(taglia, tmp_log) < 0) {
|
||||
perror("taglia_write");
|
||||
return 1;
|
||||
@ -132,7 +134,7 @@ void sendMessageFile(char *m, fileT *f, long fd_c, taglia_t *taglia, char *mlog)
|
||||
}
|
||||
|
||||
int64_t *n = calloc(1, sizeof(*n));
|
||||
if(n==NULL) {
|
||||
if(!n) {
|
||||
perror("calloc");
|
||||
goto _sendMF_cleanup;
|
||||
}
|
||||
@ -275,7 +277,7 @@ void openFile(char *filepath, int flags, queueT *q, long fd_c, taglia_t *taglia)
|
||||
taglia_update(taglia, q, 1); // removed only one file
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una openFile (flags = %x) sul file \"%s\" ha causato una capacity miss. File espulso \"%s\"\n", fd_c, flags, filepath, removed->filepath);
|
||||
sendMessageFile(MEFP, removed, fd_c, taglia, tmp_buf);
|
||||
free(removed);
|
||||
destroyFile(removed);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user