Mercurial > hg > orthanc
changeset 10:27e2bbc11200
Better signal handling
author | Administrator@jodogne-w01 |
---|---|
date | Fri, 20 Jul 2012 11:45:05 +0200 |
parents | 3a584803783e |
children | 09f1eceaccec |
files | Core/HttpServer/MongooseServer.cpp Core/Toolbox.cpp |
diffstat | 2 files changed, 19 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/HttpServer/MongooseServer.cpp Fri Jul 20 11:00:49 2012 +0200 +++ b/Core/HttpServer/MongooseServer.cpp Fri Jul 20 11:45:05 2012 +0200 @@ -339,7 +339,7 @@ } typedef boost::find_iterator<std::string::iterator> FindIterator; - typedef boost::iterator_range<std::string::iterator> Range; + typedef boost::iterator_range<char*> Range; //chunkStore.Print(); @@ -353,7 +353,7 @@ { if (last != FindIterator()) { -/* Range part(&last->back(), &it->front()); + Range part(&last->back(), &it->front()); Range content = boost::find_first(part, "\r\n\r\n"); if (content != Range()) { @@ -379,7 +379,7 @@ return chunkStore.Store(completedFile, chunkData, chunkSize, fileName->second, fileSize); } } - }*/ + } } last = it;
--- a/Core/Toolbox.cpp Fri Jul 20 11:00:49 2012 +0200 +++ b/Core/Toolbox.cpp Fri Jul 20 11:45:05 2012 +0200 @@ -32,20 +32,28 @@ #endif #if defined(__linux) +#include <signal.h> #include <unistd.h> #endif -#include <signal.h> namespace Palantir { static bool finish; +#if defined(_WIN32) + static BOOL WINAPI ConsoleControlHandler(DWORD dwCtrlType) + { + // http://msdn.microsoft.com/en-us/library/ms683242(v=vs.85).aspx + finish = true; + return true; + } +#else static void SignalHandler(int) { finish = true; } - +#endif void Toolbox::Sleep(uint32_t seconds) { @@ -72,9 +80,10 @@ void Toolbox::ServerBarrier() { +#if defined(_WIN32) + SetConsoleCtrlHandler(ConsoleControlHandler, true); +#else signal(SIGINT, SignalHandler); - -#if !defined(_WIN32) signal(SIGQUIT, SignalHandler); #endif @@ -84,9 +93,10 @@ USleep(100000); } +#if defined(_WIN32) + SetConsoleCtrlHandler(ConsoleControlHandler, false); +#else signal(SIGINT, NULL); - -#if !defined(_WIN32) signal(SIGQUIT, NULL); #endif }