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

almost done

parent 0cafa594
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -30,7 +30,7 @@ typedef struct state {
pkt_t *buffer[WINDOW_SIZE];
uint8_t head; // place last element insert +1 in the buffer (free place)
uint8_t tail; // place oldest element insert in the buffer
uint8_t last_sent_seqnum;
uint8_t next_seqnum;
uint8_t map_seqnum_to_buffer_place[SEQNUM_RANGE];
} sender_state_t;
......
Fichier ajouté
Fichier ajouté
......@@ -126,6 +126,7 @@ int main(int argc, char **argv) {
if (pfd->revents & POLLIN)
{
DEBUG("The sender is reading from the socket");
ack_received_done = handle_returning_ack_nack(state, socket_fd);
rvalue = loop_over_timers(state, socket_fd);
if ((ack_received_done == -1) || (rvalue == -1))
......@@ -138,6 +139,7 @@ int main(int argc, char **argv) {
}
else if ( !(sending_file_read_done) && (pfd->revents & POLLOUT) )
{
DEBUG("The sender will send a pkt on the socket");
sending_file_read_done = read_and_send(state, sending_fd, socket_fd);
if (sending_file_read_done == -1)
{
......
......@@ -45,22 +45,22 @@ int handle_returning_ack_nack(sender_state_t *state, int socket_fd)
return 0;
}
// From here we consider a valid ack
DEBUG("The ACK of: %d has been received", pkt_get_seqnum(pkt));
DEBUG("The ACK with the seqnum: %d has been received", pkt_get_seqnum(pkt));
uint8_t place = state->map_seqnum_to_buffer_place[pkt_get_seqnum(pkt)];
pkt_del(state->buffer[place]);
state->buffer[place] = NULL;
state->r_window_size = pkt_get_window(pkt);
if (place == state->tail)
{
for (uint8_t i = place; (state->buffer[i] == NULL) && place != state->head; i++)
for (uint8_t i = place; (state->buffer[i] == NULL) && i != state->head; i++)
{
state->tail++;
state->s_window_size++;
}
}
pkt_del(pkt);
return 0;
return state->s_window_size == MAX_WINDOW_SIZE;
}
int loop_over_timers(sender_state_t *state, int socket_fd)
......@@ -98,7 +98,6 @@ int read_and_send(sender_state_t *state, int sending_fd, int socket_fd)
if ((state->r_window_size == 0) || (state->s_window_size == 0)) return 0;
state->s_window_size--;
state->last_sent_seqnum = (uint8_t) (((uint16_t) state->last_sent_seqnum) + 1) % SEQNUM_RANGE; // Careful we need to convert to uint16_t to avoid overflow
pkt_t *pkt = pkt_new();
ssize_t nbr_byte_read = read(sending_fd, pkt->payload, MAX_PAYLOAD_SIZE);
......@@ -106,7 +105,7 @@ int read_and_send(sender_state_t *state, int sending_fd, int socket_fd)
pkt_set_tr(pkt, 0);
pkt_set_window(pkt, state->s_window_size);
pkt_set_length(pkt, nbr_byte_read);
pkt_set_seqnum(pkt, state->last_sent_seqnum);
pkt_set_seqnum(pkt, state->next_seqnum);
pkt_set_timestamp(pkt, 0); // We're free to use as we want
// We set the TR to 0 in order to calculcate the CRC on the header
......@@ -134,6 +133,7 @@ int read_and_send(sender_state_t *state, int sending_fd, int socket_fd)
state->map_seqnum_to_buffer_place[pkt_get_seqnum(pkt)] = state->head;
state->head = (state->head + 1) % WINDOW_SIZE;
state->next_seqnum = (uint8_t) (((uint16_t) state->next_seqnum) + 1) % SEQNUM_RANGE; // Careful we need to convert to uint16_t to avoid overflow
DEBUG("The pkt with seqnum: %d has been sent", pkt_get_seqnum(pkt));
// Checking if we're at the end of the file
......
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