From bfae3f356cf0ecaebf468929b72d9c0dd7adc6b3 Mon Sep 17 00:00:00 2001
From: Bastien Gorissen <bastien.gorissen@cenaero.be>
Date: Tue, 16 Nov 2010 12:49:55 +0000
Subject: [PATCH] Add an option to configure socket timeout.

---
 Common/Context.h        |  3 +++
 Common/DefaultOptions.h |  3 +++
 Common/Options.cpp      | 12 ++++++++++++
 Common/Options.h        |  1 +
 Fltk/optionWindow.cpp   |  8 +++++++-
 Fltk/solverWindow.cpp   |  2 +-
 6 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/Common/Context.h b/Common/Context.h
index e24e7226b0..ee9feeefa5 100644
--- a/Common/Context.h
+++ b/Common/Context.h
@@ -55,6 +55,8 @@ struct contextGeometryOptions {
   int matchGeomAndMesh;
 };
 
+
+
 class CTX {
  private:
   static CTX *_instance;
@@ -212,6 +214,7 @@ class CTX {
   // solver options 
   struct{
     int plugins, listen;
+    double timeout;
     std::string socketName;
   }solver;
   // print options 
diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h
index 74ef995e9b..36e2fc450f 100644
--- a/Common/DefaultOptions.h
+++ b/Common/DefaultOptions.h
@@ -1341,6 +1341,9 @@ StringXNumber SolverOptions_Number[] = {
   { F|O, "PopupMessages4" , opt_solver_popup_messages4 , 1. ,
     "Automatically display messages produced by solver 4" },
 
+  { F|O, "Timeout" , opt_solver_timeout , 5. ,
+    "Time (in seconds) before closing the socket if no connection is happening." },
+
   { 0, 0 , 0 , 0. , 0 }
 } ;
 
diff --git a/Common/Options.cpp b/Common/Options.cpp
index d15291eea2..6e12f5ce68 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -6241,6 +6241,18 @@ double opt_solver_listen(OPT_ARGS_NUM)
   return CTX::instance()->solver.listen;
 }
 
+double opt_solver_timeout(OPT_ARGS_NUM)
+{
+  if(action & GMSH_SET)
+    CTX::instance()->solver.timeout = val;
+#if defined(HAVE_FLTK)
+  if(FlGui::available() && (action & GMSH_GUI))
+    FlGui::instance()->options->solver.value[0]->value(CTX::instance()->solver.timeout);
+#endif
+  return CTX::instance()->solver.timeout;
+}
+
+
 double opt_solver_plugins(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET)
diff --git a/Common/Options.h b/Common/Options.h
index e1ccad3b0c..bb487f59a6 100644
--- a/Common/Options.h
+++ b/Common/Options.h
@@ -584,6 +584,7 @@ double opt_mesh_partition_metis_refine_algorithm(OPT_ARGS_NUM);
 double opt_mesh_partition_by_extrusion(OPT_ARGS_NUM);
 double opt_mesh_clip(OPT_ARGS_NUM);
 double opt_solver_listen(OPT_ARGS_NUM);
+double opt_solver_timeout(OPT_ARGS_NUM);
 double opt_solver_plugins(OPT_ARGS_NUM);
 double opt_solver_client_server(OPT_ARGS_NUM);
 double opt_solver_client_server0(OPT_ARGS_NUM);
diff --git a/Fltk/optionWindow.cpp b/Fltk/optionWindow.cpp
index 296bc96cc3..3a15257df3 100644
--- a/Fltk/optionWindow.cpp
+++ b/Fltk/optionWindow.cpp
@@ -495,6 +495,7 @@ static void solver_options_ok_cb(Fl_Widget *w, void *data)
     ConnectionManager::get(-1)->run("");
 
   opt_solver_socket_name(0, GMSH_SET, o->solver.input[0]->value());
+  opt_solver_timeout(0, GMSH_SET, o->solver.value[0]->value());
 
   if(CTX::instance()->fastRedraw)
     CTX::instance()->post.draw = CTX::instance()->mesh.draw = 0;
@@ -2445,8 +2446,13 @@ optionWindow::optionWindow(int deltaFontSize)
         solver.input[0]->align(FL_ALIGN_RIGHT);
         solver.input[0]->callback(solver_options_ok_cb);
 
+        solver.value[0] = new Fl_Value_Input
+          (L + 2 * WB, 2 * WB + 2 * BH, IW, BH, "Timeout (s)");
+        solver.value[0]->align(FL_ALIGN_RIGHT);
+        solver.value[0]->callback(solver_options_ok_cb);
+
         solver.butt[0] = new Fl_Check_Button
-          (L + 2 * WB, 2 * WB + 2 * BH, BW, BH, 
+          (L + 2 * WB, 2 * WB + 3 * BH, BW, BH, 
            "Always listen to incoming connection requests");
         solver.butt[0]->type(FL_TOGGLE_BUTTON);
         solver.butt[0]->callback(solver_options_ok_cb);
diff --git a/Fltk/solverWindow.cpp b/Fltk/solverWindow.cpp
index ce132c8178..028129c4f3 100644
--- a/Fltk/solverWindow.cpp
+++ b/Fltk/solverWindow.cpp
@@ -125,7 +125,7 @@ void ConnectionManager::run(std::string args)
   
   int sock;
   try{
-    sock = server->Start(command.c_str(), sockname.c_str(), 5.);
+    sock = server->Start(command.c_str(), sockname.c_str(), CTX::instance()->solver.timeout);
   }
   catch(const char *err){
     Msg::Error("%s (on socket '%s')", err, sockname.c_str());
-- 
GitLab