changeset 1193:e95e7f9eba96

fix crash when stopping Orthanc during a DICOM connection
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 20 Oct 2014 16:46:40 +0200
parents 2036c3865990
children 7d2c8d28ad87
files OrthancServer/DicomProtocol/DicomServer.cpp OrthancServer/main.cpp
diffstat 2 files changed, 16 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/DicomProtocol/DicomServer.cpp	Thu Oct 16 11:24:03 2014 +0200
+++ b/OrthancServer/DicomProtocol/DicomServer.cpp	Mon Oct 20 16:46:40 2014 +0200
@@ -190,6 +190,11 @@
 
     LOG(INFO) << "DICOM server stopping";
 
+    if (server->isThreaded_)
+    {
+      server->bagOfDispatchers_.StopAll();
+    }
+
     /* drop the network, i.e. free memory of T_ASC_Network* structure. This call */
     /* is the counterpart of ASC_initializeNetwork(...) which was called above. */
     cond = ASC_dropNetwork(&net);
@@ -403,8 +408,6 @@
     {
       pimpl_->thread_.join();
     }
-
-    bagOfDispatchers_.StopAll();
   }
 
   bool DicomServer::IsMyAETitle(const std::string& aet) const
--- a/OrthancServer/main.cpp	Thu Oct 16 11:24:03 2014 +0200
+++ b/OrthancServer/main.cpp	Mon Oct 20 16:46:40 2014 +0200
@@ -56,6 +56,8 @@
 using namespace Orthanc;
 
 
+#define ENABLE_PLUGINS  1
+
 
 class OrthancStoreRequestHandler : public IStoreRequestHandler
 {
@@ -509,20 +511,22 @@
     FilesystemHttpHandler staticResources("/app", ORTHANC_PATH "/OrthancExplorer");
 #endif
 
+#if ENABLE_PLUGINS == 1
     OrthancPlugins orthancPlugins(context);
     orthancPlugins.SetOrthancRestApi(restApi);
 
     PluginsManager pluginsManager;
     pluginsManager.RegisterServiceProvider(orthancPlugins);
     LoadPlugins(pluginsManager);
+    httpServer.RegisterHandler(orthancPlugins);
+    context.SetOrthancPlugins(orthancPlugins);
+#endif
 
-    httpServer.RegisterHandler(orthancPlugins);
     httpServer.RegisterHandler(staticResources);
     httpServer.RegisterHandler(restApi);
-    orthancPlugins.SetOrthancRestApi(restApi);
-    context.SetOrthancPlugins(orthancPlugins);
 
 
+#if ENABLE_PLUGINS == 1
     // Prepare the storage area
     if (orthancPlugins.HasStorageArea())
     {
@@ -530,6 +534,7 @@
       storage.reset(orthancPlugins.GetStorageArea());
     }
     else
+#endif
     {
       boost::filesystem::path storageDirectory = Configuration::InterpretStringParameterAsPath(storageDirectoryStr);
       LOG(WARNING) << "Storage directory: " << storageDirectory;
@@ -579,6 +584,9 @@
 
     // We're done
     LOG(WARNING) << "Orthanc is stopping";
+
+    dicomServer.Stop();
+    httpServer.Stop();
   }
 
   serverFactory.Done();