@@ -23,6 +23,7 @@ void handle_alarm(int sig){
23
23
printf ("RETRY: %d\n" ,state .retry );
24
24
if (state .retry <=5 ){
25
25
state .seq_curr = state .seq_base ;
26
+ state .seqnum = state .seq_base + 1 ;
26
27
state .retry ++ ;
27
28
state .win_size = 1 ;
28
29
}
@@ -88,7 +89,7 @@ ssize_t gbn_send(int sockfd, const void *buf, size_t len, int flags){
88
89
/*Reached end of window, wait for the correct ACK*/
89
90
while (state .seq_curr - 1 == state .seq_max ){
90
91
if (state .retry <=5 ){
91
- if (state .seq_curr > packet_num ) return (0 );
92
+ if (state .seq_base > packet_num ) return (0 );
92
93
gbnhdr * packet = malloc (sizeof (* packet ));
93
94
status = recvfrom (sockfd , packet , sizeof (* packet ), 0 , state .address , & state .socklen );
94
95
if (status != -1 ){
@@ -136,6 +137,7 @@ ssize_t gbn_recv(int sockfd, void *buf, size_t len, int flags){
136
137
printf ("INFO: DATA received successfully.\n" );
137
138
/* Receiver responds with DATAACK */
138
139
ack_packet -> type = DATAACK ;
140
+ if (state .seqnum == N + 1 )state .seqnum = 1 ;
139
141
printf ("INFO: Packet seqnum : %d State seqnum: %d\n" ,packet -> seqnum ,state .seqnum );
140
142
if (state .seqnum == packet -> seqnum ){
141
143
printf ("INFO: Received DATA packet is in sequence.\n" );
0 commit comments