added function readNfiles
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
#include <taglialegna.h>
|
||||
|
||||
#define MAXLENMESS 512
|
||||
#define LOGBUFSIZE 2048
|
||||
|
||||
#define MEOK "20" //OK
|
||||
#define MEHE "21" // help message
|
||||
@ -74,7 +75,7 @@ _sendM_cleanup:
|
||||
void sendMessageFile(char *m, fileT *f, long fd_c, taglia_t *taglia, char *mlog) {
|
||||
if(!f) {
|
||||
errno = EINVAL;
|
||||
char errmlog[2048] = "Errore negli argomenti alla funzione sendMessagefile (fileT == NULL). Messaggio originale:\n\t";
|
||||
char errmlog[2*LOGBUFSIZE] = "Errore negli argomenti alla funzione sendMessagefile (fileT == NULL). Messaggio originale:\n\t";
|
||||
strncat(errmlog, mlog, sizeof(errmlog)-strlen(errmlog)-1);
|
||||
serror(MESY, fd_c, taglia, errmlog);
|
||||
goto _sendMF_cleanup;
|
||||
@ -106,7 +107,7 @@ _sendMF_cleanup:
|
||||
void sendMessageFileN(char *m, fileT **f, int n, long fd_c, taglia_t *taglia, char *mlog) {
|
||||
if(!f) {
|
||||
errno = EINVAL;
|
||||
char errmlog[2048] = "Errore negli argomenti alla funzione sendMessagefile (fileT == NULL). Messaggio originale:\n\t";
|
||||
char errmlog[2*LOGBUFSIZE] = "Errore negli argomenti alla funzione sendMessagefile (fileT == NULL). Messaggio originale:\n\t";
|
||||
strncat(errmlog, mlog, sizeof(errmlog)-strlen(errmlog)-1);
|
||||
serror(MESY, fd_c, taglia, errmlog);
|
||||
goto _sendMFN_cleanup;
|
||||
@ -140,7 +141,7 @@ _sendMFN_cleanup:
|
||||
|
||||
void openFile(char *filepath, int flags, queueT *q, long fd_c, taglia_t *taglia) {
|
||||
// messaggio da scrivere sul logfile
|
||||
char tmp_buf[2048];
|
||||
char tmp_buf[LOGBUFSIZE];
|
||||
int n = 0;
|
||||
size_t m = sizeof(tmp_buf);
|
||||
|
||||
@ -245,7 +246,7 @@ void openFile(char *filepath, int flags, queueT *q, long fd_c, taglia_t *taglia)
|
||||
|
||||
void readFile(char *filepath, queueT *q, long fd_c, taglia_t *taglia) {
|
||||
// messaggio da scrivere sul logfile
|
||||
char tmp_buf[2048];
|
||||
char tmp_buf[LOGBUFSIZE];
|
||||
int n = 0;
|
||||
size_t m = sizeof(tmp_buf);
|
||||
|
||||
@ -280,15 +281,55 @@ void readFile(char *filepath, queueT *q, long fd_c, taglia_t *taglia) {
|
||||
}
|
||||
|
||||
|
||||
void readNFiles(char *numStr, queueT *q, long fd_c, taglia_t *taglia){
|
||||
// TODO
|
||||
void readNFiles(int num, queueT *q, long fd_c, taglia_t *taglia){
|
||||
// messaggio da scrivere sul logfile
|
||||
char tmp_buf[LOGBUFSIZE];
|
||||
int n = 0;
|
||||
size_t m = sizeof(tmp_buf);
|
||||
|
||||
if(!q || !taglia) {
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una readNFile (n = %d) e' terminata con errore\n", fd_c, num);
|
||||
errno = EINVAL;
|
||||
serror(MESY, fd_c, taglia, tmp_buf);
|
||||
return;
|
||||
}
|
||||
|
||||
int oldNum = num;
|
||||
num = (num<=0 || num>getLen(q))? getLen(q) : num;
|
||||
fileT **toSend = calloc(num, 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 */
|
||||
toSend[i] = dequeue(q);
|
||||
if(!toSend[i]) {
|
||||
n = 0;
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una readNFiles (n = %d) e' terminato con errore del server\n", fd_c, oldNum);
|
||||
perror("dequeue");
|
||||
serror(MESE, fd_c, taglia, tmp_buf);
|
||||
return;
|
||||
}
|
||||
int tmp = enqueue(q, toSend[i]);
|
||||
if(tmp<0) {
|
||||
n = 0;
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una readNFiles (n = %d) e' terminato con errore del server\n", fd_c, oldNum);
|
||||
perror("enqueue");
|
||||
serror(MESE, fd_c, taglia, tmp_buf);
|
||||
return;
|
||||
}
|
||||
n += snprintf(tmp_buf+n, m-n, "\t%d) \"%s\"\n", i, toSend[i]->filepath);
|
||||
}
|
||||
|
||||
sendMessageFileN(MEOK, toSend, num, fd_c, taglia, tmp_buf);
|
||||
free(toSend);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void writeFile(char *filepath, size_t size, queueT *q, long fd_c, taglia_t *taglia, int append) {
|
||||
// messaggio da scrivere sul logfile
|
||||
char tmp_buf[2048];
|
||||
char tmp_buf[LOGBUFSIZE];
|
||||
int n = 0;
|
||||
size_t m = sizeof(tmp_buf);
|
||||
|
||||
@ -423,7 +464,7 @@ void writeFile(char *filepath, size_t size, queueT *q, long fd_c, taglia_t *tagl
|
||||
|
||||
void lockFile(char *filepath, queueT *q, long fd_c, taglia_t *taglia, pthread_mutex_t *lock, waiting_t **waiting) {
|
||||
// messaggio da scrivere sul logfile
|
||||
char tmp_buf[2048];
|
||||
char tmp_buf[LOGBUFSIZE];
|
||||
int n = 0;
|
||||
size_t m = sizeof(tmp_buf);
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ typedef struct struct_waiting {
|
||||
* \param filepath: nome del file
|
||||
* \param flags:
|
||||
* \param q: queue in cui inserire il file
|
||||
* \param fd_c:
|
||||
* \param fd_c: owner
|
||||
* \param taglia_t:
|
||||
*/
|
||||
void openFile(char *filepath, int flags, queueT *q, long fd_c, taglia_t *taglia);
|
||||
@ -29,7 +29,7 @@ void openFile(char *filepath, int flags, queueT *q, long fd_c, taglia_t *taglia)
|
||||
void readFile(char *filepath, queueT *q, long fd_c, taglia_t *taglia);
|
||||
|
||||
// Invia al client $n file qualsiasi dalla queue
|
||||
void readNFiles(char *numStr, queueT *q, long fd_c, taglia_t *taglia);
|
||||
void readNFiles(int num, queueT *q, long fd_c, taglia_t *taglia);
|
||||
|
||||
// Scrivi dati su un file già creato (append o overwrite)
|
||||
void writeFile(char *filepath, size_t size, queueT *q, long fd_c, taglia_t *taglia, int append);
|
||||
|
||||
@ -93,7 +93,6 @@ int enqueue(queueT *q, fileT* data);
|
||||
*/
|
||||
fileT* dequeue(queueT *q);
|
||||
|
||||
|
||||
/**
|
||||
* Estrae fileT dalla coda fino ad ottenere abbastanza spazio in q.
|
||||
* \param q: puntatore alla coda
|
||||
@ -112,6 +111,7 @@ fileT ** dequeueN(queueT *q, char *filepath, size_t s);
|
||||
*/
|
||||
void voidDequeue(queueT *q);
|
||||
|
||||
|
||||
/**
|
||||
* Stampa l'intero contenuto della coda.
|
||||
* \param stream: file su cui stampare
|
||||
|
||||
Reference in New Issue
Block a user