Fix receiving SPTPS data in sptps_speed and sptps_test.
authorGuus Sliepen <guus@tinc-vpn.org>
Sun, 7 Jun 2015 21:14:48 +0000 (23:14 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Sun, 7 Jun 2015 21:17:54 +0000 (23:17 +0200)
The sptps_receive_data() was changed in commit d237efd to only process
one SPTPS record from a stream input. So now we have to put a loop
around it to ensure we process everything.

src/sptps_speed.c
src/sptps_test.c

index 4cb1221b771cd8836c04b5b3e03282cabe4fc317..4d112dd7088635fe13ce75fc73a14073d20de253 100644 (file)
@@ -47,11 +47,16 @@ static bool receive_record(void *handle, uint8_t type, const void *data, uint16_
 }
 
 static void receive_data(sptps_t *sptps) {
-       char buf[4096];
+       char buf[4096], *bufp = buf;
        int fd = *(int *)sptps->handle;
        size_t len = recv(fd, buf, sizeof buf, 0);
-       if(!sptps_receive_data(sptps, buf, len))
-               abort();
+       while(len) {
+               size_t done = sptps_receive_data(sptps, bufp, len);
+               if(!done)
+                       abort();
+               bufp += done;
+               len -= done;
+       }
 }
 
 struct timespec start;
index f83307fe5c68cf98f7ffee45a997c06177b205f6..9452ed1e0242685b36fdce31c3c4326d6a364b4c 100644 (file)
@@ -357,8 +357,19 @@ int main(int argc, char *argv[]) {
                                        fprintf(stderr, "Dropped.\n");
                                continue;
                        }
-                       if(!sptps_receive_data(&s, buf, len) && !datagram)
-                               return 1;
+                       char *bufp = buf;
+                       while(len) {
+                               size_t done = sptps_receive_data(&s, bufp, len);
+                               if(!done) {
+                                       if(!datagram)
+                                               return 1;
+                               } else {
+                                       break;
+                               }
+
+                               bufp += done;
+                               len -= done;
+                       }
                }
        }