From 93355d568583ff0d47cb986eddc8d556d70fde4f Mon Sep 17 00:00:00 2001
From: Vytor Calixto <vytorcalixto@gmail.com>
Date: Mon, 7 Dec 2015 16:27:46 -0200
Subject: [PATCH] Fixed some bugs on transmit

---
 Protocol.cpp | 8 +++++++-
 test.sh      | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/Protocol.cpp b/Protocol.cpp
index 321b3c4..1cec1b8 100644
--- a/Protocol.cpp
+++ b/Protocol.cpp
@@ -154,7 +154,13 @@ void Protocol::transmit(int sockt, int window){
             printf("astoi %i\n", response.getMessages().back().getDataAsString()[0]);
             int ackIndex = response.getMessages().back().getDataAsString()[0];
             for(int j=0; j < frame.size();) {
-                if(frame[j].index <= ackIndex) {
+                cout << "ackIndex: " << ackIndex << "frame[j].index: " << frame[j].index << endl;
+                if(ackIndex == 0) {
+                    if((frame[j].index % (MAXSIZE+1)) == 62 || (frame[j].index % (MAXSIZE+1)) == 63 || (frame[j].index % (MAXSIZE+1)) == 0) {
+                        frame.erase(frame.begin() + j);
+                        --messagesLeft;
+                    } else ++j;
+                } else if((frame[j].index % (MAXSIZE+1)) <= ackIndex) {
                     frame.erase(frame.begin() + j);
                     --messagesLeft;
                 } else ++j;
diff --git a/test.sh b/test.sh
index 710caf5..7364b6d 100755
--- a/test.sh
+++ b/test.sh
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+rm 10.txt 100.txt 1000.txt
+
 for i in {1..10}
 do
     echo -e "$i\n">>10.txt
-- 
GitLab