diff --git a/CHANGELOG b/CHANGELOG index 46abcd48..bea2ae1a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,6 +9,12 @@ https://glvis.org +Version 4.5.1 (development) +=========================== + +- Added the option ('-no-ex') to run GLVis in non-exclusive setting when the + server starts listening on the next available port instead of aborting. + Version 4.5 released on Feb 6, 2026 =================================== diff --git a/glvis.cpp b/glvis.cpp index 6f85c8d0..a64c72a1 100644 --- a/glvis.cpp +++ b/glvis.cpp @@ -158,7 +158,7 @@ class Session void GLVisServer(int portnum, bool save_stream, bool fix_elem_orient, bool save_coloring, string plot_caption, bool secure, - bool headless = false) + bool headless = false, bool exclusive = true) { std::vector current_sessions; string data_type; @@ -203,10 +203,26 @@ void GLVisServer(int portnum, bool save_stream, bool fix_elem_orient, #endif const int backlog = 128; - socketserver server(portnum, backlog); - if (server.good()) + unique_ptr server; + if (!exclusive) + { + for (;; portnum++) + { + server = make_unique(portnum, backlog); + if (server->good()) { break; } + } + } + else + { + server = make_unique(portnum, backlog); + } + if (server->good()) { cout << "Waiting for data on port " << portnum << " ..." << endl; + if (!exclusive) + { + cerr << "GLVIS_SERVER_PORT=" << portnum << endl; + } } else { @@ -223,7 +239,7 @@ void GLVisServer(int portnum, bool save_stream, bool fix_elem_orient, isock.reset(secure ? new socketstream(*params) : new socketstream(false)); #endif vector> input_streams; - while (server.accept(*isock) < 0) + while (server->accept(*isock) < 0) { #ifdef GLVIS_DEBUG cout << "GLVis: server.accept(...) failed." << endl; @@ -293,7 +309,7 @@ void GLVisServer(int portnum, bool save_stream, bool fix_elem_orient, break; } // read next available socket stream - while (server.accept(*isock) < 0) + while (server->accept(*isock) < 0) { #ifdef GLVIS_DEBUG cout << "GLVis: server.accept(...) failed." << endl; @@ -388,6 +404,7 @@ int main (int argc, char *argv[]) const char *font_name = string_default; int portnum = 19916; bool persistent = true; + bool exclusive = true; int multisample = GetMultisample(); double line_width = GetLineWidth(); double ms_line_width = GetLineWidthMS(); @@ -461,6 +478,9 @@ int main (int argc, char *argv[]) args.AddOption(&persistent, "-pr", "--persistent", "-no-pr", "--no-persistent", "Keep server running after all windows are closed."); + args.AddOption(&exclusive, "-ex", "--exclusive", + "-no-ex", "--no-exclusive", + "Exclusively block the given port or take the next available."); args.AddOption(&secure, "-sec", "--secure-sockets", "-no-sec", "--standard-sockets", "Enable or disable GnuTLS secure sockets."); @@ -696,7 +716,8 @@ int main (int argc, char *argv[]) std::thread serverThread{GLVisServer, portnum, save_stream, win.data_state.fix_elem_orient, win.data_state.save_coloring, - win.plot_caption, secure, win.headless}; + win.plot_caption, secure, win.headless, + exclusive}; // Start message loop in main thread MainThreadLoop(win.headless, persistent);