diff --git a/Common/GmshRemote.cpp b/Common/GmshRemote.cpp index 0a320a84306d43ae3e929088564523c3735824cf..b1935478ea4d9c32f5e67d17a333f01b06bf3192 100644 --- a/Common/GmshRemote.cpp +++ b/Common/GmshRemote.cpp @@ -66,8 +66,8 @@ int GmshRemote() break; } - int type, length; - if(!client->ReceiveHeader(&type, &length)){ + int type, length, swap; + if(!client->ReceiveHeader(&type, &length, &swap)){ client->Error("Did not receive message header: stopping remote Gmsh..."); break; } diff --git a/Common/GmshSocket.h b/Common/GmshSocket.h index f513a56758bfbae403809416f6e1de8ea0ca60d3..a112d4043e846ceff588e57c7f0fdec93b7cb628 100644 --- a/Common/GmshSocket.h +++ b/Common/GmshSocket.h @@ -185,20 +185,20 @@ class GmshSocket{ if(num > 5) num = 5; SendString(GMSH_OPTION_1 + num - 1, str); } - int ReceiveHeader(int *type, int *len) + int ReceiveHeader(int *type, int *len, int *swap) { - bool swap = false; + *swap = 0; if(_ReceiveData(type, sizeof(int))){ if(*type < 0) return 0; if(*type > 65535){ // the data comes from a machine with different endianness and // we must swap the bytes - swap = true; + *swap = 1; _SwapBytes((char*)type, sizeof(int), 1); } if(_ReceiveData(len, sizeof(int))){ if(*len < 0) return 0; - if(swap) _SwapBytes((char*)len, sizeof(int), 1); + if(*swap) _SwapBytes((char*)len, sizeof(int), 1); return 1; } } diff --git a/Common/VertexArray.cpp b/Common/VertexArray.cpp index 2bfe2c8d63c103927521a4468f187fd460ef070d..b708ff13fd8c8872417751de9130280eec52bcf6 100644 --- a/Common/VertexArray.cpp +++ b/Common/VertexArray.cpp @@ -252,15 +252,14 @@ char *VertexArray::toChar(int num, std::string name, int type, double min, doubl return bytes; } -void VertexArray::fromChar(const char *bytes) +void VertexArray::fromChar(const char *bytes, int swap) { + // FIXME deal with swap + int is = sizeof(int), ds = sizeof(double), index = 0; int num; memcpy(&num, &bytes[index], is); index += is; - if(num > 65535) - Msg::Error("Should swap data in vertex array stream"); - int ss; memcpy(&ss, &bytes[index], is); index += is; if(ss){ std::vector<char> name(ss); diff --git a/Common/VertexArray.h b/Common/VertexArray.h index 47e5158ebcd0b6c8a9210a57c14760a2a390cfbb..49eeb2b2b341276d12d55f0149da6392dfe20915 100644 --- a/Common/VertexArray.h +++ b/Common/VertexArray.h @@ -166,7 +166,7 @@ class VertexArray{ // network) char *toChar(int num, std::string name, int type, double min, double max, int numsteps, double time, SBoundingBox3d bbox, int &len); - void fromChar(const char *bytes); + void fromChar(const char *bytes, int swap); }; #endif diff --git a/Fltk/solverWindow.cpp b/Fltk/solverWindow.cpp index 0f79a18170d6fcd1d2cf071470e7112ff6e1c1b0..e919f787cee8b20176cac7c395701e288b6136d0 100644 --- a/Fltk/solverWindow.cpp +++ b/Fltk/solverWindow.cpp @@ -155,8 +155,8 @@ void ConnectionManager::run(std::string args) if(stop || _pid < 0 || (prog.empty() && !CTX::instance()->solver.listen)) break; - int type, length; - if(!server->ReceiveHeader(&type, &length)){ + int type, length, swap; + if(!server->ReceiveHeader(&type, &length, &swap)){ Msg::Error("Did not receive message header: stopping server"); break; } @@ -225,7 +225,7 @@ void ConnectionManager::run(std::string args) case GmshSocket::GMSH_VERTEX_ARRAY: { int n = PView::list.size(); - PView::fillVertexArray(this, length, message); + PView::fillVertexArray(this, length, message, swap); if(n != (int)PView::list.size()) FlGui::instance()->updateViews(); drawContext::global()->draw(); diff --git a/Post/PView.h b/Post/PView.h index 70a0259596ce70a59ad6b23d08f3c9be7f5287fa..d621a93e4e1b6d6ddc815739da0f303db652a45d 100644 --- a/Post/PView.h +++ b/Post/PView.h @@ -119,7 +119,7 @@ class PView{ // fill a vertex array using a raw stream of bytes static void fillVertexArray(ConnectionManager *remote, int length, - const char *data); + const char *data, int swap); // smoothed normals smooth_normals *normals; diff --git a/Post/PViewVertexArrays.cpp b/Post/PViewVertexArrays.cpp index 567bd0fed6da2c1fb0707a4f4b49c6eb7434c7f8..b477e77000aa5322baf8440000900d1917ac9506 100644 --- a/Post/PViewVertexArrays.cpp +++ b/Post/PViewVertexArrays.cpp @@ -1142,7 +1142,8 @@ void PView::fillVertexArrays() init(this); } -void PView::fillVertexArray(ConnectionManager *remote, int length, const char *bytes) +void PView::fillVertexArray(ConnectionManager *remote, int length, + const char *bytes, int swap) { int is = sizeof(int), ds = sizeof(double); @@ -1150,6 +1151,11 @@ void PView::fillVertexArray(ConnectionManager *remote, int length, const char *b Msg::Error("Too few bytes to create vertex array: %d", length); return; } + + if(swap){ + Msg::Error("Should swap bytes in vertex array--not implemented yet"); + return; + } std::string name; @@ -1201,22 +1207,22 @@ void PView::fillVertexArray(ConnectionManager *remote, int length, const char *b case 1: if(p->va_points) delete p->va_points; p->va_points = new VertexArray(1, 100); - p->va_points->fromChar(bytes); + p->va_points->fromChar(bytes, swap); break; case 2: if(p->va_lines) delete p->va_lines; p->va_lines = new VertexArray(2, 100); - p->va_lines->fromChar(bytes); + p->va_lines->fromChar(bytes, swap); break; case 3: if(p->va_triangles) delete p->va_triangles; p->va_triangles = new VertexArray(3, 100); - p->va_triangles->fromChar(bytes); + p->va_triangles->fromChar(bytes, swap); break; case 4: if(p->va_vectors) delete p->va_vectors; p->va_vectors = new VertexArray(2, 100); - p->va_vectors->fromChar(bytes); + p->va_vectors->fromChar(bytes, swap); break; default: Msg::Error("Cannot fill vertex array of type %d", type); diff --git a/utils/solvers/c++/GmshSocket.h b/utils/solvers/c++/GmshSocket.h index 6f8951da02cf830f9fa8b833fd4a26047b6c4918..d8d9fbbf363ed22f21730627a3cff96bb5f246d1 100644 --- a/utils/solvers/c++/GmshSocket.h +++ b/utils/solvers/c++/GmshSocket.h @@ -185,25 +185,26 @@ class GmshSocket{ if(num > 5) num = 5; SendString(GMSH_OPTION_1 + num - 1, str); } - int ReceiveHeader(int *type, int *len) + int ReceiveHeader(int *type, int *len, int *swap) { - bool swap = false; + *swap = 0; if(_ReceiveData(type, sizeof(int))){ if(*type < 0) return 0; if(*type > 65535){ // the data comes from a machine with different endianness and // we must swap the bytes - swap = true; + *swap = 1; _SwapBytes((char*)type, sizeof(int), 1); } if(_ReceiveData(len, sizeof(int))){ if(*len < 0) return 0; - if(swap) _SwapBytes((char*)len, sizeof(int), 1); + if(*swap) _SwapBytes((char*)len, sizeof(int), 1); return 1; } } return 0; } + // str should be allocated with size (len+1) int ReceiveString(int len, char *str) { if(_ReceiveData(str, len) == len) {