#include <string>
#include <map>
Go to the source code of this file.
Classes | |
struct | ltstr |
comparison operator for standard template library map More... | |
struct | file_struct |
structure identifying a file More... | |
struct | database_struct |
database of files for the FS More... | |
Defines | |
#define | MAX_FS_ERROR_COUNTER 3 |
maximum number of generic error before terminating the listening thread | |
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[]) |
USAGE:
FS [DFR_IP_address_or_domain_name_for_FSs] \ [DFR_port_for_FSs] [port_for_CLs] \ [file1] [max_clients_for_file1] \ [file2] [max_clients_for_file2] \ [file3] [max_clients_for_file3] \ ...
for each file the user must specify the absoulte path or the relative path from the current working directory, and the number of maximum clients for that file
this function has also the role of the thread manager, first it fills the file database private of the DFR, but before signaling to the DFR the availability of a file, the FS needs to be ready to accept requests from clients. this is the reason why the first thing we do is creating a listening socket for clients thread
Definition in file FS.h.
#define MAX_FS_ERROR_COUNTER 3 |
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 116 of file CL.cpp.
References CL_s_body(), file_struct::cur_clients, DEB, database_struct::files, FS_id, FS_s_body(), file_struct::full_name, init_sd_cli(), init_sd_serv(), INT_AS_STRING_BYTES, listen(), LOG, file_struct::max_clients, mode_1(), mode_2(), 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().