working -R

This commit is contained in:
elvis
2022-04-29 21:04:45 +02:00
parent 6a7b018f25
commit 59ac9663c9
5 changed files with 69 additions and 38 deletions

View File

@ -164,7 +164,7 @@ _sendMF_cleanup:
}
// invio il messaggio al client e poi n file
void sendMessageFileN(char *m, fileT **f, int n, long fd_c, taglia_t *taglia, char *mlog) {
void sendMessageFileN(char *m, fileT **f, int64_t n, long fd_c, taglia_t *taglia, char *mlog) {
if(!f) {
errno = EINVAL;
char errmlog[2*LOGBUFSIZE] = "Errore negli argomenti alla funzione sendMessagefile (fileT == NULL). Messaggio originale:\n\t";
@ -360,13 +360,13 @@ void readNFiles(int num, queueT *q, long fd_c, taglia_t *taglia){
}
int oldNum = num;
num = (num<=0 || num>getLen(q))? getLen(q) : num;
fileT **toSend = calloc(num, sizeof(fileT *));
int64_t ntosend = (num<=0 || num>getLen(q))? getLen(q) : num;
fileT **toSend = calloc(ntosend, sizeof(fileT *));
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
for(int i=0;i<num;++i) { /* TODO: fix here */
for(int i=0;i<ntosend;++i) {
toSend[i] = dequeue(q);
if(!toSend[i]) {
n = 0;
@ -386,7 +386,7 @@ void readNFiles(int num, queueT *q, long fd_c, taglia_t *taglia){
n += snprintf(tmp_buf+n, m-n, "\t%d) \"%s\"\n", i, toSend[i]->filepath);
}
sendMessageFileN(MEOK, toSend, num, fd_c, taglia, tmp_buf);
sendMessageFileN(MEOK, toSend, ntosend, fd_c, taglia, tmp_buf);
free(toSend);
return;
}