Subject: New API call for nxcom (nx-libs) NXTransCleanupForReconnect
From: Nito Martinez <[email-masked]>
To: [email-masked]
Date: Fri, 08 May 2015 00:40:24 +0200

Package: nx-libs
Version: 3.5.0.28

Description:

The following patch includes support for a new API call 
NXTransCleanupForReconnect, which basically clears the state of nxcomp 
proxy side (modified nxproxy), so that a reconnection is possible.

Rationale:

Usually nxproxy clears the status of the connection by doing an exit and 
launching a new nxproxy. This strategy does not work for applications in 
IOS which do not allow forking.

Special care has been taking to not modify any of the other nxcomp code.

Regards,

Nito
diff --git a/nx-libs-3.5.0.22/nxcomp/Loop.cpp b/nx-libs-3.5.0.22/nxcomp/Loop.cpp
index 8c19467..16b757a 100644
--- a/nx-libs-3.5.0.22/nxcomp/Loop.cpp
+++ b/nx-libs-3.5.0.22/nxcomp/Loop.cpp
@@ -1311,6 +1311,11 @@ void NXTransCleanup()
   HandleCleanup();
 }

+void NXTransCleanupForReconnect()
+{
+  HandleCleanupForReconnect();
+}
+
 //
 // Check the parameters for subsequent
 // initialization of the NX transport.
@@ -4835,6 +4840,28 @@ int StartKeeper()
   return 1;
 }

+void HandleCleanupForReconnect()
+{
+  #ifdef TEST
+  *logofs << "Loop: Going to clean up system resources for Reconnect "
+          << "in process '" << getpid() << "'.\n"
+          << logofs_flush;
+  #endif
+  handleTerminatedInLoop();
+  DisableSignals();
+  if (control)
+    CleanupChildren();
+  CleanupListeners();
+  CleanupSockets();
+  CleanupKeeper();
+  CleanupStreams();
+  CleanupLocal();
+  CleanupGlobal();
+  RestoreSignals();
+  ServerCache::lastInitReply.set(0,NULL);
+  ServerCache::lastKeymap.set(0,NULL);
+  ServerCache::getKeyboardMappingLastMap.set(0,NULL);
+}
 void HandleCleanup(int code)
 {
   #ifdef TEST
diff --git a/nx-libs-3.5.0.22/nxcomp/Misc.h b/nx-libs-3.5.0.22/nxcomp/Misc.h
index 21a5030..0cc3969 100644
--- a/nx-libs-3.5.0.22/nxcomp/Misc.h
+++ b/nx-libs-3.5.0.22/nxcomp/Misc.h
@@ -140,6 +140,7 @@ void HandleShutdown() __attribute__((noreturn));
 extern "C"
 {
   void HandleCleanup(int code = 0) __attribute__((noreturn));
+  void HandleCleanupForReconnect();
 }

 //
diff --git a/nx-libs-3.5.0.22/nxcomp/NX.h b/nx-libs-3.5.0.22/nxcomp/NX.h
index 2dbf686..0e4734e 100644
--- a/nx-libs-3.5.0.22/nxcomp/NX.h
+++ b/nx-libs-3.5.0.22/nxcomp/NX.h
@@ -442,6 +442,14 @@ extern int NXTransParseEnvironment(const char *env, int force);

 extern void NXTransCleanup(void) __attribute__((noreturn));

+/*
+ * Cleans up the global and local state
+ * (the same way as NXTransCleanup does)
+ * but does not exit the process
+ * Needed for IOS platform
+ */
+extern void NXTransCleanupForReconnect(void);
+
 extern const char* NXVersion();
 extern int NXMajorVersion();
 extern int NXMinorVersion();