Consolidate how to run the FLTK loop in one place
diff --git a/vncviewer/CConn.cxx b/vncviewer/CConn.cxx
index 78eadb5..fb136b5 100644
--- a/vncviewer/CConn.cxx
+++ b/vncviewer/CConn.cxx
@@ -228,13 +228,7 @@
 
 void CConn::blockCallback()
 {
-  int next_timer;
-
-  next_timer = Timer::checkTimeouts();
-  if (next_timer == 0)
-    next_timer = INT_MAX;
-
-  Fl::wait((double)next_timer / 1000.0);
+  run_mainloop();
 
   if (should_exit())
     throw rdr::Exception("Termination requested");
diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx
index a2bc029..d71cb7f 100644
--- a/vncviewer/vncviewer.cxx
+++ b/vncviewer/vncviewer.cxx
@@ -128,6 +128,20 @@
   fl_message("%s", about_text());
 }
 
+void run_mainloop()
+{
+  int next_timer;
+
+  next_timer = Timer::checkTimeouts();
+  if (next_timer == 0)
+    next_timer = INT_MAX;
+
+  if (Fl::wait((double)next_timer / 1000.0) < 0.0) {
+    vlog.error(_("Internal FLTK error. Exiting."));
+    exit(-1);
+  }
+}
+
 #ifdef __APPLE__
 static void about_callback(Fl_Widget *widget, void *data)
 {
@@ -590,18 +604,8 @@
 
   CConn *cc = new CConn(vncServerName, sock);
 
-  while (!exitMainloop) {
-    int next_timer;
-
-    next_timer = Timer::checkTimeouts();
-    if (next_timer == 0)
-      next_timer = INT_MAX;
-
-    if (Fl::wait((double)next_timer / 1000.0) < 0.0) {
-      vlog.error(_("Internal FLTK error. Exiting."));
-      break;
-    }
-  }
+  while (!exitMainloop)
+    run_mainloop();
 
   delete cc;
 
diff --git a/vncviewer/vncviewer.h b/vncviewer/vncviewer.h
index 4d0566b..c98c2e9 100644
--- a/vncviewer/vncviewer.h
+++ b/vncviewer/vncviewer.h
@@ -24,5 +24,6 @@
 void exit_vncviewer(const char *error = NULL);
 bool should_exit();
 void about_vncviewer();
+void run_mainloop();
 
 #endif