Skip to content
Extraits de code Groupes Projets
Valider 7b98416e rédigé par Vany Ingenzi's avatar Vany Ingenzi
Parcourir les fichiers

Corrected the write stats functions

parent 5a2574f8
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -109,7 +109,7 @@ int wait_for_client(int sfd) ...@@ -109,7 +109,7 @@ int wait_for_client(int sfd)
return 0; return 0;
} }
void write_stats_to_file(const char * pathname, transfer_stats_t * stats_file) void write_stats_to_file(const char * pathname, transfer_stats_t * stats_file, agents_t caller)
{ {
if (pathname == NULL || stats_file == NULL) if (pathname == NULL || stats_file == NULL)
return; return;
...@@ -150,25 +150,27 @@ void write_stats_to_file(const char * pathname, transfer_stats_t * stats_file) ...@@ -150,25 +150,27 @@ void write_stats_to_file(const char * pathname, transfer_stats_t * stats_file)
ret = sprintf((char *) &buffer, "packet_ignored:%llu\n", stats_file->packet_ignored); ret = sprintf((char *) &buffer, "packet_ignored:%llu\n", stats_file->packet_ignored);
ret = write(fd, buffer, strlen(buffer)); ret = write(fd, buffer, strlen(buffer));
#ifdef __RECEIVER_UTILS_ if (caller == RECEIVER)
ret = sprintf((char *) &buffer, "packet_duplicated:%llu\n", stats_file->packet_duplicated); {
ret = write(fd, buffer, strlen(buffer)); ret = sprintf((char *) &buffer, "packet_duplicated:%llu\n", stats_file->packet_duplicated);
ret = write(fd, buffer, strlen(buffer));
ret = sprintf((char *) &buffer, "packet_recovered:%llu\n", stats_file->packet_recovered); ret = sprintf((char *) &buffer, "packet_recovered:%llu\n", stats_file->packet_recovered);
ret = write(fd, buffer, strlen(buffer)); ret = write(fd, buffer, strlen(buffer));
#endif }
#ifdef __SENDER_UTILS_H_
ret = sprintf((char *) &buffer, "min_rtt:%llu ms\n", stats_file->min_rtt);
ret = write(fd, buffer, strlen(buffer));
ret = sprintf((char *) &buffer, "max_rtt:%llu ms\n", stats_file->max_rtt); if (caller == SENDER)
ret = write(fd, buffer, strlen(buffer)); {
ret = sprintf((char *) &buffer, "min_rtt:%llu ms\n", stats_file->min_rtt);
ret = write(fd, buffer, strlen(buffer));
ret = sprintf((char *) &buffer, "packet_retransmitted:%llu\n", stats_file->packet_retransmitted); ret = sprintf((char *) &buffer, "max_rtt:%llu ms\n", stats_file->max_rtt);
ret = write(fd, buffer, strlen(buffer)); ret = write(fd, buffer, strlen(buffer));
#endif
ret = sprintf((char *) &buffer, "packet_retransmitted:%llu\n", stats_file->packet_retransmitted);
ret = write(fd, buffer, strlen(buffer));
}
close(fd); close(fd);
ret--; // dump ret--; // dump
DEBUG("Wrote the transfer statistics to %s.", pathname); DEBUG("Wrote the transfer statistics to %s.", pathname);
......
...@@ -30,17 +30,19 @@ typedef struct __attribute__((__packed__)) ...@@ -30,17 +30,19 @@ typedef struct __attribute__((__packed__))
unsigned long long int nack_sent; unsigned long long int nack_sent;
unsigned long long int nack_received; unsigned long long int nack_received;
unsigned long long int packet_ignored; unsigned long long int packet_ignored;
#ifdef __RECEIVER_UTILS_
unsigned long long int packet_duplicated; unsigned long long int packet_duplicated;
unsigned long long int packet_recovered; unsigned long long int packet_recovered;
#endif
#ifdef __SENDER_UTILS_H_
unsigned long long int min_rtt; unsigned long long int min_rtt;
unsigned long long int max_rtt; unsigned long long int max_rtt;
unsigned long long int packet_retransmitted; unsigned long long int packet_retransmitted;
#endif
} transfer_stats_t; } transfer_stats_t;
/* The type of agents */
typedef enum{
SENDER,
RECEIVER,
}agents_t;
/** /**
* @brief Resolve the resource name to an usable IPv6 address * @brief Resolve the resource name to an usable IPv6 address
...@@ -83,9 +85,11 @@ int wait_for_client(int sfd); ...@@ -83,9 +85,11 @@ int wait_for_client(int sfd);
* *
* @param pathname: The pathname to the stats file. * @param pathname: The pathname to the stats file.
* @param stats_file: Pointer to the stats file output. * @param stats_file: Pointer to the stats file output.
* @param caller: To know the caller of the function.
*
* *
* @returns In case of an error it is printed on the stderr. * @returns In case of an error it is printed on the stderr.
*/ */
void write_stats_to_file(const char * pathname, transfer_stats_t * stats_file); void write_stats_to_file(const char * pathname, transfer_stats_t * stats_file, agents_t caller);
#endif #endif
\ No newline at end of file
...@@ -650,7 +650,7 @@ void receiver_read_write_loop(int sfd, const char * pathname) ...@@ -650,7 +650,7 @@ void receiver_read_write_loop(int sfd, const char * pathname)
reception_loop(pfd, state); reception_loop(pfd, state);
DEBUG("Done the transfer with done status being %s", (state->transfer_done) ? "true" : "false"); DEBUG("Done the transfer with done status being %s", (state->transfer_done) ? "true" : "false");
write_stats_to_file(pathname, state->stats); write_stats_to_file(pathname, state->stats, RECEIVER);
state_del(state); state_del(state);
free(pfd); free(pfd);
} }
\ No newline at end of file
...@@ -39,7 +39,7 @@ sender_state_t *state_new(bool fec_enabled) ...@@ -39,7 +39,7 @@ sender_state_t *state_new(bool fec_enabled)
void state_del(sender_state_t *state, const char * pathname) void state_del(sender_state_t *state, const char * pathname)
{ {
write_stats_to_file(pathname, state->stats); write_stats_to_file(pathname, state->stats, SENDER);
// To be sure, we free the pkt that might not have been freed (in case of an error or timeout) // To be sure, we free the pkt that might not have been freed (in case of an error or timeout)
for (uint8_t i = 0; i < WINDOW_SIZE; i++) for (uint8_t i = 0; i < WINDOW_SIZE; i++)
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter