Skip to content
Snippets Groups Projects
Commit 40979a23 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

simplify gmsh server + add timout so we avoid runaway processes

parent 35b080c6
No related branches found
No related tags found
No related merge requests found
......@@ -23,38 +23,49 @@ int GmshDaemon(std::string socket)
client.Start();
client.Info("Server sucessfully started. Listening...");
// read large data file,
// initialize mpi job,
// then wait for commands to execute:
bool stop = false;
// initialize mpi job, then wait for commands to execute...
while(1){
if(stop) break;
// wait at most 1 second for data
if(!client.Select(1, 0)){
// stop the server if we have no communications for 60 seconds
int ret = client.Select(60, 0);
if(!ret){
client.Info("Timout: stopping server...");
break;
}
else if(ret < 0){
client.Error("Error on select: stopping server...");
break;
}
int type, length;
if(client.ReceiveHeader(&type, &length)){
if(!client.ReceiveHeader(&type, &length)){
client.Error("Did not receive message header: stopping server...");
break;
}
char *msg = new char[length + 1];
if(client.ReceiveString(length, msg)){
if(!client.ReceiveString(length, msg)){
client.Error("Did not receive message body: stopping server...");
delete [] msg;
break;
}
std::ostringstream tmp;
tmp << "Hello! I've received msg type=" << type << " len=" << length
<< " str=" << msg;
client.Info(tmp.str().c_str());
switch(type){
case GmshSocket::GMSH_STOP:
{
if(type == GmshSocket::GMSH_STOP){
client.Info("Stopping connection!");
stop = true;
}
break;
case GmshSocket::GMSH_VERTEX_ARRAY:
{
}
else if(type == GmshSocket::GMSH_VERTEX_ARRAY){
// create and send a vertex array
if(PView::list.size()){
PView *view = PView::list[0];
view->getOptions()->intervalsType = PViewOptions::Iso;
view->fillVertexArrays();
PViewData *data = view->getData();
int len;
char *ss = view->va_triangles->toChar
(view->getNum(), 3, data->getMin(), data->getMax(),
......@@ -63,15 +74,11 @@ int GmshDaemon(std::string socket)
delete [] ss;
}
}
break;
case GmshSocket::GMSH_SPEED_TEST:
{
else if(type == GmshSocket::GMSH_SPEED_TEST){
std::string huge(500000000, 'a');
client.SpeedTest(huge.c_str());
}
break;
case GmshSocket::GMSH_PARSE_STRING:
{
else if(type == GmshSocket::GMSH_PARSE_STRING){
std::ostringstream v;
v << "View \"test\" {\n";
for(int i = 0; i < 200; i++){
......@@ -84,16 +91,8 @@ int GmshDaemon(std::string socket)
v << "};BoundingBox;\n";
client.ParseString(v.str().c_str());
}
break;
}
}
delete [] msg;
}
}
else{
// ping the server so we automatically crash of it goes down :-)
printf("printf ping!\n");
client.Info("Ping!");
client.Error("Unknown message type: ignoring...");
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment