From eb3826285379521ffad32d5228f87e1fc8cdc864 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Sun, 13 Sep 2009 18:46:00 +0000
Subject: [PATCH] send/receive vertex array over socket ok

---
 Common/GmshSocket.h    |  4 ++--
 Common/VertexArray.cpp | 13 +------------
 2 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/Common/GmshSocket.h b/Common/GmshSocket.h
index 9d188b0b86..22d41a1a4d 100644
--- a/Common/GmshSocket.h
+++ b/Common/GmshSocket.h
@@ -80,8 +80,8 @@ class GmshSocket{
     int remaining = bytes;
     do {
       int len = recv(_sock, buf + sofar, remaining, 0);
-      if(len <= 0)
-        return 0;
+      if(len == 0) break; // we're done!
+      if(len < 0) return -1; // error
       sofar += len;
       remaining -= len;
     } while(remaining > 0);
diff --git a/Common/VertexArray.cpp b/Common/VertexArray.cpp
index e125aff23f..7faf3a52d7 100644
--- a/Common/VertexArray.cpp
+++ b/Common/VertexArray.cpp
@@ -223,18 +223,13 @@ char *VertexArray::toChar(int num, int &len)
   int vs = vn * sizeof(float), ns = nn * sizeof(char), cs = cn * sizeof(unsigned char);
   int is = sizeof(int);
 
-  FILE *fp = fopen("toChar.txt", "w");
-  for(unsigned int i = 0; i < _vertices.size(); i++)
-    fprintf(fp, "toChar vertex %d = %f\n", i, _vertices[i]);
-  fclose(fp);
-
   len = 5 * is + vs + ns + cs;
   char *data = new char[len];
   int index = 0;
   memcpy(&data[index], &num, is); index += is;
   memcpy(&data[index], &_numVerticesPerElement, is); index += is;
   memcpy(&data[index], &vn, is); index += is;
-  memcpy(&data[index], &_vertices[0], vs); index + vs;
+  memcpy(&data[index], &_vertices[0], vs); index += vs;
   memcpy(&data[index], &nn, is); index += is;
   memcpy(&data[index], &_normals[0], ns); index += ns;
   memcpy(&data[index], &cn, is); index += is;
@@ -269,10 +264,4 @@ void VertexArray::fromChar(const char *data, bool swap)
   int cn; memcpy(&cn, &data[index], is); index += is;
   _colors.resize(cn); int cs = cn * sizeof(unsigned char); 
   memcpy(&_colors[0], &data[index], cs); index += cs;
-
-
-  FILE *fp = fopen("fromChar.txt", "w");
-  for(unsigned int i = 0; i < _vertices.size(); i++)
-    fprintf(fp, "from char vertex %d = %f\n", i, _vertices[i]);
-  fclose(fp);
 }
-- 
GitLab