Skip to content
Extraits de code Groupes Projets
Valider 25a92034 rédigé par Samuel de Meester de Ravestein's avatar Samuel de Meester de Ravestein
Parcourir les fichiers

fix NACK for sender

parent 844c53dd
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -140,7 +140,7 @@ int main(int argc, char **argv) { ...@@ -140,7 +140,7 @@ int main(int argc, char **argv) {
break; break;
} }
if (pfd->revents & POLLIN) if ((pfd->revents & POLLIN) && (pfd->revents & POLLOUT))
{ {
DEBUG("The sender is reading from the socket"); DEBUG("The sender is reading from the socket");
rvalue = handle_returning_ack_nack(state, socket_fd); rvalue = handle_returning_ack_nack(state, socket_fd);
......
...@@ -114,15 +114,17 @@ int handle_returning_ack_nack(sender_state_t *state, int socket_fd) ...@@ -114,15 +114,17 @@ int handle_returning_ack_nack(sender_state_t *state, int socket_fd)
// Handling NACK: // Handling NACK:
if (pkt_type == PTYPE_NACK) if (pkt_type == PTYPE_NACK)
{ {
if (state->map_seqnum_to_buffer_place[seqnum] == OUT_OFF_WINDOW) uint8_t place = state->map_seqnum_to_buffer_place[seqnum];
if (place == OUT_OFF_WINDOW)
{ {
DEBUG("The NACK with the seqnum: %d is out of the sended window so it has been discarded", seqnum); DEBUG("The NACK with the seqnum: %d is out of the sended window so it has been discarded", seqnum);
} }
else else
{ {
DEBUG("The NACK with the seqnum: %d has been received", seqnum); DEBUG("The NACK with the seqnum: %d has been received, so the pkt will be sent back", seqnum);
state->r_window_size = r_window; state->r_window_size = r_window - 1; // -1 Because the receiver doesn't count yet the sended pkt
if (send_pkt(state, pkt, seqnum, socket_fd) == -1) return -1; pkt_t *n_pkt = state->buffer[place];
if (send_pkt(state, n_pkt, place, socket_fd) == -1) return -1;
} }
} }
// Handling ACK: // Handling ACK:
...@@ -153,13 +155,14 @@ int handle_returning_ack_nack(sender_state_t *state, int socket_fd) ...@@ -153,13 +155,14 @@ int handle_returning_ack_nack(sender_state_t *state, int socket_fd)
return 0; return 0;
} }
} }
// Some pkt need to be acked // Some pkt need to be acknowledged
else else
{ {
state->r_window_size = r_window; state->r_window_size = r_window;
uint8_t upper_bound = (place_last_ack + 1) % WINDOW_SIZE; // The oldest seqnum sended uint8_t upper_bound = (place_last_ack + 1) % WINDOW_SIZE; // The oldest seqnum sended
DEBUG("The sender is cumulatively acknowledging [%d : %d[ (place in the buffer)", state->tail, upper_bound); DEBUG("The sender is cumulatively acknowledging [%d : %d[ (place in the buffer) | [%d, %d[ (seqnum)",
state->tail, upper_bound, pkt_get_seqnum(state->buffer[state->tail]), seqnum_nack);
// A do while is necessary here in case we want to make a full revolution (ack from 1 to 1 not included for example) // A do while is necessary here in case we want to make a full revolution (ack from 1 to 1 not included for example)
do do
{ {
......
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