#include "../include/FS.h"
#include "../include/command.h"
#include "../include/utility.h"
#include "../include/cond_comp.h"
#include <netdb.h>
#include <arpa/inet.h>
#include <libgen.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <cstdlib>
#include <cstring>
Go to the source code of this file.
Functions | |
int | get_filesize (const char *filename) |
helper function used to get the size in bytes of a file | |
void * | req_server (void *csk) |
body of the request serving thread | |
void * | listen (void *sock) |
body of the listening server | |
int | main (int argc, char *argv[]) |
Variables | |
database_struct | database |
FS database. | |
string | FS_id |
string used as a FS identification for output message |
int get_filesize | ( | const char * | filename | ) |
helper function used to get the size in bytes of a file
filename | | abosulute or relative path of the file return -1 if error, size in bytes of the file if everything ok |
Definition at line 21 of file FS.cpp.
Referenced by req_server().
void* listen | ( | void * | sock | ) |
body of the listening server
before starting to add the specified files to the DFR, one thread with this function as a body is created, which starts accepting requests from clients. the reason to do this before starting to add files to the DFR is avoid long pending time of clients, let's explain this with an example:
sock | | initialized listening socket ready for accept CL requests |
Definition at line 135 of file FS.cpp.
References FS_id, LOG, MAX_FS_ERROR_COUNTER, and req_server().
Referenced by init_sd_serv(), and main().
int main | ( | int | argc, | |
char * | argv[] | |||
) |
Definition at line 160 of file FS.cpp.
References file_struct::cur_clients, DEB, database_struct::files, FS_id, file_struct::full_name, init_sd_cli(), init_sd_serv(), INT_AS_STRING_BYTES, listen(), LOG, file_struct::max_clients, database_struct::mutex, OK, register_file, and send_command().
void* req_server | ( | void * | csk | ) |
body of the request serving thread
when a request is received by the listening thread, then a req_server thread is created, which has this function as body. the newly created thread detaches himself from the parent thread, and starts serving the request coming from the CL.
note that this means that there is NOT a thread for each client, but a thread for each client request
csk | | socket used to communicate with the client |
Definition at line 28 of file FS.cpp.
References file_struct::cur_clients, ERR_FILE_NOT_EXISTS, ERR_TOO_MANY_CLIENTS, ERR_UNKNOWN, command::file_name, database_struct::files, FS_id, file_struct::full_name, get_file, get_filesize(), command::id, INT_AS_STRING_BYTES, LOG, file_struct::max_clients, database_struct::mutex, OK, receive_command(), and reply_command().
Referenced by listen().
string FS_id |
string used as a FS identification for output message
Definition at line 19 of file FS.cpp.
Referenced by listen(), main(), and req_server().