bugssss
This commit is contained in:
137
lib/api/api.c
137
lib/api/api.c
@ -8,6 +8,7 @@
|
||||
#include <sys/time.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <api.h>
|
||||
#include <conn.h>
|
||||
@ -40,7 +41,9 @@ typedef struct files_s {
|
||||
typedef struct openfiles_s {
|
||||
int numOfFiles;
|
||||
files_t *f; // list of files
|
||||
int validwDir; // 1 if wDir is allocated
|
||||
char *wDir; // for files sent from the server after openFile
|
||||
int validrDir; // 1 if rDir is allocated
|
||||
char *rDir; // for files read from the server
|
||||
char *createdAndLocked; // path of the last file that was created and locked
|
||||
int print; // whether to print
|
||||
@ -64,7 +67,7 @@ typedef struct response_s {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/* variabili globali */
|
||||
static int fd_skt; // descriptor of the socket
|
||||
static long fd_skt; // descriptor of the socket
|
||||
static char socketName[SOCKNAMEMAX] = ""; // name of the socket
|
||||
static openfiles_t *openedFiles = NULL;
|
||||
|
||||
@ -86,6 +89,8 @@ int reciveData(response_t *res, int expected);
|
||||
int storeFilesInDirectory(const char *dirname, int n, recivedFile_t *rf);
|
||||
// frees memory inside response_t element
|
||||
void freeResponse(response_t *res);
|
||||
// creates the global variable
|
||||
int createOpenedFiles(void);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -96,18 +101,10 @@ int openConnection(const char* sockname, int msec, const struct timespec abstime
|
||||
}
|
||||
|
||||
if(!openedFiles) {
|
||||
openedFiles = calloc(1, sizeof(openedFiles));
|
||||
if(!openedFiles) {
|
||||
perror("calloc");
|
||||
if(createOpenedFiles()<0) {
|
||||
perror("createOpenedfiles");
|
||||
return -1;
|
||||
}
|
||||
openedFiles->f = NULL;
|
||||
openedFiles->numOfFiles = 0;
|
||||
openedFiles->createdAndLocked = NULL;
|
||||
openedFiles->rDir = NULL;
|
||||
openedFiles->wDir = NULL;
|
||||
openedFiles->print = 0;
|
||||
openedFiles->out = NULL;
|
||||
}
|
||||
|
||||
struct sockaddr_un sa;
|
||||
@ -170,17 +167,6 @@ int closeConnection(const char* sockname) {
|
||||
}
|
||||
|
||||
memset(socketName, 0, SOCKNAMEMAX);
|
||||
|
||||
if (openedFiles) {
|
||||
if(openedFiles->createdAndLocked)
|
||||
free(openedFiles->createdAndLocked);
|
||||
if(openedFiles->wDir)
|
||||
free(openedFiles->wDir);
|
||||
if(openedFiles->rDir)
|
||||
free(openedFiles->rDir);
|
||||
free(openedFiles);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -206,7 +192,7 @@ int openFile(const char* pathname, int flags) {
|
||||
}
|
||||
|
||||
// invio al server la stringa "openFile|$(pathname)|$(flags)"
|
||||
long len = strlen("openFile")+1+strlen(pathname)+1+sizeof(flags)+1;
|
||||
long len = strlen("openFile")+1+strlen(pathname)+1+((int)log10(flags)+1)+1;
|
||||
char *cmd = malloc(len);
|
||||
if(!cmd) {
|
||||
perror("malloc");
|
||||
@ -214,6 +200,7 @@ int openFile(const char* pathname, int flags) {
|
||||
}
|
||||
memset(cmd, 0, len);
|
||||
snprintf(cmd, len, "openFile|%s|%d", pathname, flags);
|
||||
len = strnlen(cmd, len);
|
||||
|
||||
// send cmd
|
||||
if (writen(fd_skt, &len, sizeof(long)) == -1) {
|
||||
@ -336,6 +323,7 @@ int readFile(const char* pathname, void** buf, size_t* size) {
|
||||
}
|
||||
memset(cmd, 0, len);
|
||||
snprintf(cmd, len, "readFile|%s", pathname);
|
||||
len = strnlen(cmd, len);
|
||||
|
||||
// send cmd
|
||||
if (writen(fd_skt, &len, sizeof(long)) == -1) {
|
||||
@ -440,7 +428,7 @@ int readNFiles(int N, const char* dirname) {
|
||||
}
|
||||
|
||||
// invio al server la stringa "readNFile|$(N)"
|
||||
long len = strlen("readNFile")+1+sizeof(N)+1;
|
||||
long len = strlen("readNFile")+1+((int)log10(N)+1)+1;
|
||||
char *cmd = malloc(len);
|
||||
if(!cmd) {
|
||||
perror("malloc");
|
||||
@ -448,6 +436,7 @@ int readNFiles(int N, const char* dirname) {
|
||||
}
|
||||
memset(cmd, 0, len);
|
||||
snprintf(cmd, len, "readNFile|%d", N);
|
||||
len = strnlen(cmd, len);
|
||||
|
||||
// send cmd
|
||||
if (writen(fd_skt, &len, sizeof(long)) == -1) {
|
||||
@ -558,7 +547,7 @@ int writeFile(const char* pathname, const char* dirname) {
|
||||
}
|
||||
|
||||
if (openedFiles->print) {
|
||||
fprintf(openedFiles->out, "Dimensione: %ld B\n", size);
|
||||
fprintf(openedFiles->out, "Dimensione: %ldB ", size);
|
||||
fflush(openedFiles->out);
|
||||
}
|
||||
|
||||
@ -568,7 +557,7 @@ int writeFile(const char* pathname, const char* dirname) {
|
||||
}
|
||||
|
||||
// invio al server la stringa "writeFile|$(pathname)|$(size)"
|
||||
long len = strlen("writeFile")+1+strlen(pathname)+1+sizeof(size)+1;
|
||||
long len = strlen("writeFile")+1+strlen(pathname)+1+((int) log10(size)+1)+1;
|
||||
char *cmd = malloc(len);
|
||||
if(!cmd) {
|
||||
perror("malloc");
|
||||
@ -577,6 +566,7 @@ int writeFile(const char* pathname, const char* dirname) {
|
||||
}
|
||||
memset(cmd, 0, len);
|
||||
snprintf(cmd, len, "writeFile|%s|%zu", pathname, size);
|
||||
len = strnlen(cmd, len);
|
||||
|
||||
// send cmd
|
||||
if (writen(fd_skt, &len, sizeof(long)) == -1) {
|
||||
@ -596,10 +586,11 @@ int writeFile(const char* pathname, const char* dirname) {
|
||||
response_t *res = calloc(1, sizeof(response_t));
|
||||
if(!res){
|
||||
perror("calloc");
|
||||
free(cmd);
|
||||
free(content);
|
||||
free(cmd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(reciveData(res, 0) < 0) { // 0 because if we get a MEOK we don't expect files
|
||||
// errno is set by reciveData
|
||||
freeResponse(res);
|
||||
@ -608,7 +599,6 @@ int writeFile(const char* pathname, const char* dirname) {
|
||||
free(content);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(res->meerrno != 0) { // errno from server
|
||||
freeResponse(res);
|
||||
errno = res->meerrno;
|
||||
@ -657,13 +647,30 @@ int writeFile(const char* pathname, const char* dirname) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// recive response
|
||||
if(reciveData(res, 0) < 0) { // 0 because if we get a MEOK we don't expect files
|
||||
// errno is set by reciveData
|
||||
freeResponse(res);
|
||||
free(res);
|
||||
free(cmd);
|
||||
free(content);
|
||||
return -1;
|
||||
}
|
||||
if(res->meerrno != 0) { // errno from server
|
||||
freeResponse(res);
|
||||
errno = res->meerrno;
|
||||
free(res);
|
||||
free(cmd);
|
||||
free(content);
|
||||
return -1;
|
||||
}
|
||||
|
||||
freeResponse(res);
|
||||
free(res);
|
||||
|
||||
free(cmd);
|
||||
|
||||
free(content);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1111,7 +1118,7 @@ int removeFile(const char* pathname) {
|
||||
}
|
||||
|
||||
free(cmd);
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -1123,21 +1130,33 @@ int setDirectory(char* Dir, int rw) {
|
||||
}
|
||||
|
||||
if (rw == 1) {
|
||||
if(openedFiles->wDir)
|
||||
if(openedFiles->validwDir) {
|
||||
free(openedFiles->wDir);
|
||||
openedFiles->wDir = NULL;
|
||||
}
|
||||
openedFiles->validwDir = 1;
|
||||
openedFiles->wDir = malloc(strlen(Dir)+1);
|
||||
strncpy(openedFiles->wDir, Dir, strlen(Dir)+1);
|
||||
} else {
|
||||
if(openedFiles->rDir)
|
||||
if(openedFiles->validrDir) {
|
||||
free(openedFiles->rDir);
|
||||
openedFiles->rDir = NULL;
|
||||
}
|
||||
openedFiles->validrDir = 1;
|
||||
openedFiles->rDir = malloc(strlen(Dir)+1);
|
||||
strncpy(openedFiles->rDir, Dir, strlen(Dir)+1);
|
||||
}
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void printInfo(int p, FILE *stream) {
|
||||
// 1 prints, 0 does not print
|
||||
if(!openedFiles) {
|
||||
if(createOpenedFiles()<0) {
|
||||
perror("createOpenedfiles");
|
||||
return;
|
||||
}
|
||||
}
|
||||
openedFiles->print = (p)? 1: 0;
|
||||
openedFiles->out = stream;
|
||||
return;
|
||||
@ -1152,7 +1171,7 @@ int reciveData(response_t *res, int expected) {
|
||||
}
|
||||
|
||||
int readnres;
|
||||
readnres = readn(fd_skt, res->ME, sizeof(res->ME));
|
||||
readnres = readn(fd_skt, &res->ME, sizeof(res->ME));
|
||||
if(readnres <= 0) {
|
||||
// readn sets errno
|
||||
return -1;
|
||||
@ -1303,7 +1322,6 @@ _nofile:
|
||||
free(res->rf);
|
||||
res->rf = NULL;
|
||||
|
||||
|
||||
if(strncmp(res->ME, MEOK, sizeof(res->ME))==0){
|
||||
// simple ok response
|
||||
res->meerrno = 0;
|
||||
@ -1457,8 +1475,12 @@ void freeResponse(response_t *res) {
|
||||
return;
|
||||
if(res->numfiles>0 && res->rf){
|
||||
for(int i=0;i<res->numfiles;++i){
|
||||
free(res->rf[i].path);
|
||||
free(res->rf[i].file);
|
||||
if(res->rf[i].path)
|
||||
free(res->rf[i].path);
|
||||
res->rf[i].path = NULL;
|
||||
if(res->rf[i].file)
|
||||
free(res->rf[i].file);
|
||||
res->rf[i].file = NULL;
|
||||
}
|
||||
free(res->rf);
|
||||
}
|
||||
@ -1541,7 +1563,7 @@ int removeOpenFile(const char *pathname) {
|
||||
openedFiles->f = tmp->next;
|
||||
free(tmp->filename);
|
||||
free(tmp);
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
files_t *prc = NULL;
|
||||
@ -1563,8 +1585,9 @@ int removeOpenFile(const char *pathname) {
|
||||
}
|
||||
|
||||
int closeEveryFile() {
|
||||
if (!openedFiles)
|
||||
if (openedFiles == NULL)
|
||||
return 0;
|
||||
|
||||
if (openedFiles->numOfFiles > 0 && openedFiles->f != NULL) {
|
||||
files_t *tmp = openedFiles->f;
|
||||
files_t *prc = NULL;
|
||||
@ -1580,5 +1603,41 @@ int closeEveryFile() {
|
||||
}
|
||||
}
|
||||
}
|
||||
if(openedFiles->createdAndLocked) {
|
||||
free(openedFiles->createdAndLocked);
|
||||
openedFiles->createdAndLocked = NULL;
|
||||
}
|
||||
if(openedFiles->validrDir) {
|
||||
free(openedFiles->rDir);
|
||||
openedFiles->validrDir = 0;
|
||||
openedFiles->rDir = NULL;
|
||||
}
|
||||
if(openedFiles->validwDir) {
|
||||
free(openedFiles->wDir);
|
||||
openedFiles->validwDir = 0;
|
||||
openedFiles->wDir = NULL;
|
||||
}
|
||||
|
||||
fprintf(stdout, "\nhere\n");
|
||||
fflush(stdout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int createOpenedFiles(void) {
|
||||
openedFiles = calloc(1, sizeof(openedFiles));
|
||||
if(!openedFiles) {
|
||||
perror("calloc");
|
||||
return -1;
|
||||
}
|
||||
openedFiles->f = NULL;
|
||||
openedFiles->numOfFiles = 0;
|
||||
openedFiles->createdAndLocked = NULL;
|
||||
openedFiles->validrDir = 0;
|
||||
openedFiles->rDir = NULL;
|
||||
openedFiles->validwDir = 0;
|
||||
openedFiles->wDir = NULL;
|
||||
openedFiles->print = 0;
|
||||
openedFiles->out = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -118,6 +118,8 @@ size_t taglia_log(taglia_t *taglia, char *buf) {
|
||||
}
|
||||
pthread_mutex_unlock(&taglia->m);
|
||||
|
||||
fflush(taglia->file);
|
||||
|
||||
return n+m;
|
||||
|
||||
_error_taglia_log_mutex:
|
||||
|
||||
@ -59,7 +59,7 @@ void sendMessage(char *m, long fd_c, taglia_t *taglia, char *mlog) {
|
||||
m = MEOK;
|
||||
}
|
||||
|
||||
if(writen(fd_c, m, strnlen(m, MAXLENMESS)+1) < 0) {
|
||||
if(writen(fd_c, m, strnlen(m, MAXLENMESS)) < 0) {
|
||||
perror("writen");
|
||||
goto _sendM_cleanup;
|
||||
}
|
||||
@ -213,14 +213,14 @@ void openFile(char *filepath, int flags, queueT *q, long fd_c, taglia_t *taglia)
|
||||
fileT *removed = NULL; // file che è stato rimosso
|
||||
|
||||
if(found && create) { // si vuole creare il file ma esiste già
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una openFile (flags = %x) sul file \"%s\" e' terminata con errore\n", fd_c, flags, filepath);
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una openFile (flags = %x) sul file \"%s\" ma il file esiste già\n", fd_c, flags, filepath);
|
||||
errno = EEXIST;
|
||||
serror(MENT, fd_c, taglia, tmp_buf);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!found && !create) { // si vuole aprire e non creare un file inesistente
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una openFile (flags = %x) sul file \"%s\" e' terminato con errore\n", fd_c, flags, filepath);
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una openFile (flags = %x) sul file \"%s\" ma il file non esiste\n", fd_c, flags, filepath);
|
||||
errno = ENOENT;
|
||||
serror(MENT, fd_c, taglia, tmp_buf);
|
||||
return;
|
||||
@ -228,7 +228,7 @@ void openFile(char *filepath, int flags, queueT *q, long fd_c, taglia_t *taglia)
|
||||
|
||||
if(found && !create) {
|
||||
if(openFileInQueue(q, filepath, lock, fd_c) == -1) {
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una openFile (flags = %x) sul file \"%s\" e' terminato con errore\n", fd_c, flags, filepath);
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una openFile (flags = %x) sul file \"%s\" e' terminato con errore del server\n", fd_c, flags, filepath);
|
||||
perror("openFileInQueue");
|
||||
serror(MESE, fd_c, taglia, tmp_buf);
|
||||
return;
|
||||
@ -399,22 +399,22 @@ void writeFile(char *filepath, size_t size, queueT *q, long fd_c, taglia_t *tagl
|
||||
fileT *f = NULL;
|
||||
f = find(q, filepath);
|
||||
if(!f) { // file is not present
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una writeFile (append = %x) sul file \"%s\", dimensione = %ld, e' terminata con errore\n", fd_c, append, filepath, size);
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una writeFile (append = %x) sul file \"%s\", dimensione = %ld, e' terminata con errore, file non trovato\n", fd_c, append, filepath, size);
|
||||
errno = ENOENT;
|
||||
serror(MENT, fd_c, taglia, tmp_buf);
|
||||
destroyFile(f);
|
||||
return;
|
||||
}
|
||||
|
||||
// file non aperto || !append => locked || lock ma non si è proprietari
|
||||
if(!f->open || (append || f->O_LOCK) || (f->O_LOCK && f->owner != fd_c)) {
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una writeFile (append = %x) sul file \"%s\", dimensione = %ld, e' terminata con errore\n", fd_c, append, filepath, size);
|
||||
// file non aperto || non append e nessuna lock || lock ma non si è proprietari
|
||||
if(!f->open || (!append && !f->O_LOCK) || (f->O_LOCK && f->owner != fd_c)) {
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una writeFile (append = %x) sul file \"%s\", dimensione = %ld, e' terminata con errore, non proprietario del file\n", fd_c, append, filepath, size);
|
||||
errno = EPERM;
|
||||
serror(MENT, fd_c, taglia, tmp_buf);
|
||||
destroyFile(f);
|
||||
return;
|
||||
}
|
||||
int trueSizeAdded = 0; // we may have alredy some space allocated
|
||||
long trueSizeAdded = 0; // we may have alredy some space allocated
|
||||
if(append) {
|
||||
trueSizeAdded = size - f->size + f->valid;
|
||||
} else {
|
||||
@ -422,19 +422,19 @@ void writeFile(char *filepath, size_t size, queueT *q, long fd_c, taglia_t *tagl
|
||||
}
|
||||
destroyFile(f); // not needed anymore
|
||||
|
||||
fileT **removed = NULL; // array that may (worst case) hold all files to be sent to the client
|
||||
|
||||
if(trueSizeAdded + getSize(q) > q->maxSize) { // writing would be more than capacity
|
||||
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
|
||||
removed = dequeueN(q, filepath, trueSizeAdded);
|
||||
if(!removed) { // internal error
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una writeFile (append = %x) sul file \"%s\", dimensione = %ld, e' terminata con errore\n", fd_c, append, filepath, size);
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una writeFile (append = %x) sul file \"%s\", dimensione = %ld, e' terminata con errore del server\n", fd_c, append, filepath, size);
|
||||
errno = ENOENT;
|
||||
serror(MESY, fd_c, taglia, tmp_buf);
|
||||
return;
|
||||
}
|
||||
int ln = 0;
|
||||
fileT *tmp = removed[ln];
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una writeFile (append = %x) sul file \"%s\", dimensione = %ld, e' terminata con successo. Ha causato una capacity miss e ha fatto espellere i seguenti file:", fd_c, append, filepath, size);
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una writeFile (append = %x) sul file \"%s\", dimensione = %ld, e' terminata con successo, allocando %ld B in memoria. Ha causato una capacity miss e ha fatto espellere i seguenti file:", fd_c, append, filepath, size, trueSizeAdded);
|
||||
while(tmp!=NULL) {
|
||||
n += snprintf(tmp_buf+n, m-n, " \"%s\"", tmp->filepath);
|
||||
++ln;
|
||||
@ -448,12 +448,12 @@ void writeFile(char *filepath, size_t size, queueT *q, long fd_c, taglia_t *tagl
|
||||
destroyFile(removed[i]);
|
||||
}
|
||||
free(removed);
|
||||
// now we can write the actual file
|
||||
|
||||
// now we can get the actual file
|
||||
void *content = NULL;
|
||||
content = malloc(size);
|
||||
content = calloc(size, sizeof(char));
|
||||
if(!content) {
|
||||
perror("malloc");
|
||||
perror("calloc");
|
||||
return;
|
||||
}
|
||||
if((readn(fd_c, content, size)) == -1) {
|
||||
@ -461,30 +461,41 @@ void writeFile(char *filepath, size_t size, queueT *q, long fd_c, taglia_t *tagl
|
||||
return;
|
||||
}
|
||||
|
||||
n = 0;
|
||||
|
||||
if(append) {
|
||||
if(appendFileInQueue(q, filepath, content, size, fd_c) == -1) {
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una writeFile (append = %x) sul file \"%s\", dimensione = %ld, errore del server\n", fd_c, append, filepath, size);
|
||||
serror(MESY, fd_c, taglia, tmp_buf);
|
||||
perror("appendFileInQueue");
|
||||
free(content);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if(writeFileInQueue(q, filepath, content, size, fd_c) == -1) {
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una writeFile (append = %x) sul file \"%s\", dimensione = %ld, errore del server\n", fd_c, append, filepath, size);
|
||||
serror(MESY, fd_c, taglia, tmp_buf);
|
||||
perror("writeFileInQueue");
|
||||
free(content);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una writeFile (append = %x) sul file \"%s\", dimensione = %ld, e' terminata con successo\n", fd_c, append, filepath, size);
|
||||
sendMessage(MEOK, fd_c, taglia, tmp_buf);
|
||||
|
||||
taglia_update(taglia, q, 0);
|
||||
free(content);
|
||||
return;
|
||||
}
|
||||
|
||||
// no dequeue
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una writeFile (append = %x) sul file \"%s\", dimensione = %ld, accettata la richiesta.\n", fd_c, append, filepath, size);
|
||||
sendMessage(MEOK, fd_c, taglia, tmp_buf);
|
||||
// non c'è ancora bisogno di rimuovere file
|
||||
void *content = NULL;
|
||||
content = malloc(size);
|
||||
content = calloc(size, sizeof(char));
|
||||
if(!content) {
|
||||
perror("malloc");
|
||||
perror("calloc");
|
||||
return;
|
||||
}
|
||||
if(readn(fd_c, content, size) == -1) {
|
||||
@ -492,23 +503,27 @@ void writeFile(char *filepath, size_t size, queueT *q, long fd_c, taglia_t *tagl
|
||||
return;
|
||||
}
|
||||
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una writeFile (append = %x) sul file \"%s\", dimensione = %ld, e' terminata con successo\n", fd_c, append, filepath, size);
|
||||
n = 0;
|
||||
|
||||
if(append) {
|
||||
if(appendFileInQueue(q, filepath, content, size, fd_c) == -1) {
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una writeFile (append = %x) sul file \"%s\", dimensione = %ld, errore del server\n", fd_c, append, filepath, size);
|
||||
serror(MESY, fd_c, taglia, tmp_buf);
|
||||
perror("appendFileInQueue");
|
||||
free(content);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if(writeFileInQueue(q, filepath, content, size, fd_c) == -1) {
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una writeFile (append = %x) sul file \"%s\", dimensione = %ld, errore del server\n", fd_c, append, filepath, size);
|
||||
serror(MESY, fd_c, taglia, tmp_buf);
|
||||
perror("writeFileInQueue");
|
||||
free(content);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
taglia_write(taglia, tmp_buf);
|
||||
n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una writeFile (append = %x) sul file \"%s\", dimensione = %ld, e' terminata con successo\n", fd_c, append, filepath, size);
|
||||
sendMessage(MEOK, fd_c, taglia, tmp_buf);
|
||||
|
||||
taglia_update(taglia, q, 0);
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ static inline int readn(long fd, void *buf, size_t size) {
|
||||
int r;
|
||||
char *bufptr = (char*)buf;
|
||||
while(left>0) {
|
||||
if ((r=read((int)fd ,bufptr,left)) == -1) {
|
||||
if ((r=read(fd ,bufptr,left)) == -1) {
|
||||
if (errno == EINTR) continue;
|
||||
return -1;
|
||||
}
|
||||
@ -50,7 +50,7 @@ static inline int writen(long fd, void *buf, size_t size) {
|
||||
int r;
|
||||
char *bufptr = (char*)buf;
|
||||
while(left>0) {
|
||||
if ((r=write((int) fd, bufptr, left)) == -1) {
|
||||
if ((r=write(fd, bufptr, left)) == -1) {
|
||||
if (errno == EINTR) continue;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
* tipo del messaggio
|
||||
*/
|
||||
typedef struct msg {
|
||||
int len;
|
||||
long len;
|
||||
char *str;
|
||||
} msg_t;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user