include/FS.h File Reference

#include <string>
#include <map>

Include dependency graph for FS.h:

This graph shows which files directly or indirectly include this file:

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[])


Detailed Description

this file defines the FSs main() function which contains the code for a test file server. the test file server has no user interface and it's behaviour can be configured only using parameters from the command line

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 Documentation

#define MAX_FS_ERROR_COUNTER   3

maximum number of generic error before terminating the listening thread

Definition at line 39 of file FS.h.

Referenced by listen().


Function Documentation

int get_filesize ( const char *  filename  ) 

helper function used to get the size in bytes of a file

Parameters:
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:

  • FS A has 5000 files to add to the DFR
  • CL B wants the first of those files, but FS A has not added it to the DFR yet
  • CL B asks the DFR for notification on file 1
  • FS A adds file 1 to the DFR
  • DFR notifies CL B, which goes on asking the FS for that file
  • if we had started accepting requests only after injecting in the DFR all the 5000 files a long time could elapse before CL B is served

Parameters:
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[] 
)

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

Parameters:
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().


Generated on Sat Jun 13 21:06:30 2009 for DistributedFileRepository by  doxygen 1.5.8