src_FS/FS.cpp File Reference

#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>

Include dependency graph for FS.cpp:

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


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


Variable Documentation

FS database.

Definition at line 16 of file FS.cpp.

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


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