Newer
Older
#ifndef __SENDER_UTILS_H_
#define __SENDER_UTILS_H_
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/socket.h>
#include "log.h"
#include "our_utils.h"
#include "packet_interface.h"
#define TIMER_LIMIT 2000 // we're in micro seconds
/** When buffer field are not used they MUST be set to NULL */
typedef struct state {
uint8_t r_window_size; // reception buffer space
uint8_t s_window_size; // sender (our) buffer space
suseconds_t timers[WINDOW_SIZE]; // Time in MICRO seconds
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 map_seqnum_to_buffer_place[SEQNUM_RANGE];
} sender_state_t;
sender_state_t *state_new();
void state_del(sender_state_t *state);
int handle_returning_ack_nack(sender_state_t *state, int socket_fd);
int loop_over_timers(sender_state_t *state, int socket_fd);
int read_and_send(sender_state_t *state, int sending_fd, int socket_fd);