RealtimeCompLab2

Dependencies:   mbed

Fork of PPP-Blinky by Nicolas Nackel

Revision:
34:8a6fbc73a7f1
Parent:
33:b5a86ff03f3d
Child:
35:e7068df4d971
--- a/main.cpp	Thu Jan 05 03:23:18 2017 +0000
+++ b/main.cpp	Thu Jan 05 04:14:35 2017 +0000
@@ -464,7 +464,7 @@
     if (flags & (1<<8)) flagInfo[8]='N';
     flagInfo[9]=0; // null terminate string
     if (v0) {
-        debug(("Flags %s Seq %d Ack %d", flagInfo, seq, ack));
+        debug(("Flags %s Seq %u Ack %u", flagInfo, seq, ack));
     }
 }
 
@@ -516,8 +516,11 @@
     dataLen = 0; // most of our responses will have zero TCP data, only a header
     
     if ( ((flagsTCP & TCP_FLAG_FIN) != 0) && ((flagsTCP & TCP_FLAG_ACK) != 0) ) {
-          return; // ACK and FIN - we are done
-    } else if ( ((flagsTCP & ~TCP_FLAG_ACK) == 0) && ((flagsTCP & TCP_FLAG_ACK) != 0) ) {
+            if (ack <= ppp.seq) return; // their idea of our sequence is larger
+            int temp = ack; // remember what they thought
+            ack = seq + incomingLen; // ack their sequence
+            ppp.seq = temp; // adopt their calculation of our sequence
+   } else if ( ((flagsTCP & ~TCP_FLAG_ACK) == 0) && ((flagsTCP & TCP_FLAG_ACK) != 0) ) {
         if (incomingLen > 0) {  // they sent data in the ack
             ack = seq + incomingLen; // acknowledge the number of bytes they sent
             seq = ppp.seq; // confirm our current sequence position
@@ -565,7 +568,7 @@
             if (v0) {
                 debug(("HTTP GET dataLen %d*32=%d Header %d Content-Length %d Total %d Margin %d\n",dataLen/32,dataLen,nHeader,contentLength,n,dataLen-n-1));
             }
-        } else if ( strncmp(dataStart, "GET /", 4) == 0) {
+        } else if ( strncmp(dataStart, "GET /", 4) == 0) { // all other files get 404 not found
             flagbitstcp[1] = TCP_FLAG_ACK | TCP_FLAG_FIN; // close connection after delivering page
             dataLen = 5*32; // this block has to hold the web page below, but keep it under 1k
             memset(dataStart,'x', dataLen ); // initialize the block