src_common/command.cpp File Reference

#include "../include/command.h"
#include <cstdlib>
#include <cstring>

Include dependency graph for command.cpp:

Go to the source code of this file.

Functions

int send_command (int sock, command com, int *rep_data_size, char **rep_data)
 sends a synchronized command
int receive_command (int sock, command *com)
 receives a synchronized command
int reply_command (int sock, int status, int add_bytes, const char *add_data)
 sends a response message to a previously received command
int receive_sft_reply (int sock, int *rep_data_size, char **rep_data)
 receives a response message


Function Documentation

int receive_command ( int  sock,
command com 
)

receives a synchronized command

receive_command() is declared friend to allow use of fill_from_string() private member function

See also:
receive_command()
this function receives a singular command from a channel which must have been previously initialized. It will not return until a command is received, or an error occours. received parameters are saved in the command object pointed by com.

Parameters:
sock | socket from which to receive the command
com | command object to be filled for the caller
Returns:
0 if everything is ok, -1 otherwise

Definition at line 161 of file command.cpp.

References command::fill_from_string().

Referenced by CL_req_s_body(), FS_req_s_body(), mode_2(), and req_server().

int receive_sft_reply ( int  sock,
int *  rep_data_size,
char **  rep_data 
)

receives a response message

this function SHOULD be used only by the CLs, when they ask a notification and the DFR finally signals the disponibility of the file to the client, the server sends a notify command to the client. If the client replies to this message with an OK status, the server assumes that a start_file_transfer command has been initiated by the client, this means that the DFR will reply with a start_file_transfer response message. the CL can use this function to catch that response message.

Parameters:
sock | socket on which the CL wants to wait for the response
rep_data | pointer to data to be returned to the client (allocated dynamically)
rep_data_size | pointer to an integer to return the size of the rep_data
Returns:
a state code from the following list
See also:
OK

ERR_FILE_NOT_REGISTERED

ERR_TOO_MANY_CLIENTS

ERR_FILE_NOT_EXISTS

ERR_NO_TRANSFER

ERR_NO_NOTIFICATION

ERR_UNKNOWN

Definition at line 213 of file command.cpp.

References ERR_UNKNOWN.

Referenced by mode_2().

int reply_command ( int  sock,
int  status,
int  add_bytes,
const char *  add_data 
)

sends a response message to a previously received command

each command needs a response message, allowing the corresponding send_command() call to return to the caller. the reply message is built as follows:

<status_integer|size_of_additional_data|additional_data>

status_integer is one of the following values:

  • OK
  • ERR_FILE_NOT_REGISTERED
  • ERR_TOO_MANY_CLIENTS
  • ERR_FILE_NOT_EXISTS
  • ERR_NO_TRANSFER
  • ERR_NO_NOTIFICATION
  • ERR_UNKNOWN

size_of_additional_data is an integer-as-string field which is the number of bytes in the following field.

additional_data is the data the responder is sending to the commander which has previously sent a command.

Parameters:
sock | socket to send the response message
status | status of the request, as described above
add_bytes | number of bytes to be sent as additional data (0 if no additional data)
add_data | pointer to additional data to be sent (NULL if no additional data)
Returns:
0 if everything is ok, -1 otherwise

Definition at line 178 of file command.cpp.

References INT_AS_STRING_BYTES.

Referenced by FS_req_s_body(), mode_2(), req_server(), serve_end_file_transfer(), serve_reg_notification(), and serve_start_file_transfer().

int send_command ( int  sock,
command  com,
int *  rep_data_size,
char **  rep_data 
)

sends a synchronized command

send_command() is declared friend to allow use of to_string() private member function

See also:
send_command()
this function sends a command to a remote server or client, the connection must be previously established. It will not return until some data are received in response on the socket, this means a state message and eventually some data.

the response data will be one of the following, depending on the command:

  • register_file -> no data (NULL)
  • unregister_file -> no data (NULL)
  • start_file_transfer -> information on how to contact the associated FS
  • end_file_transfer -> no data (NULL)
  • reg_notification -> no data (NULL)
  • notify -> no data (NULL)
  • get_file -> transferred file

Parameters:
sock | socket to contact the opposite end of the channel
com | command to be sent
rep_data | pointer to data to be returned to the caller (allocated dynamically)
rep_data_size | pointer to an integer to return the size of the rep_data, if any
Returns:
a state code from the following list
See also:
OK

ERR_FILE_NOT_REGISTERED

ERR_TOO_MANY_CLIENTS

ERR_FILE_NOT_EXISTS

ERR_NO_TRANSFER

ERR_NO_NOTIFICATION

ERR_UNKNOWN

Definition at line 112 of file command.cpp.

References ERR_UNKNOWN, and command::to_string().

Referenced by main(), mode_1(), mode_2(), send_end_command(), serve_reg_notification(), and transfer_file().


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