comparison Core/Toolbox.cpp @ 2009:e2dd40abce72

catching SIGHUP signal
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 09 Jun 2016 17:25:34 +0200
parents e29aea2349b9
children 4dafe2a0d3ab
comparison
equal deleted inserted replaced
2008:dc82c754dcaa 2009:e2dd40abce72
109 #endif 109 #endif
110 110
111 111
112 namespace Orthanc 112 namespace Orthanc
113 { 113 {
114 static bool finish; 114 static bool finish_;
115 static ServerBarrierEvent barrierEvent_;
115 116
116 #if defined(_WIN32) 117 #if defined(_WIN32)
117 static BOOL WINAPI ConsoleControlHandler(DWORD dwCtrlType) 118 static BOOL WINAPI ConsoleControlHandler(DWORD dwCtrlType)
118 { 119 {
119 // http://msdn.microsoft.com/en-us/library/ms683242(v=vs.85).aspx 120 // http://msdn.microsoft.com/en-us/library/ms683242(v=vs.85).aspx
120 finish = true; 121 finish_ = true;
122 barrierEvent_ = ServerBarrierEvent_Stop;
121 return true; 123 return true;
122 } 124 }
123 #else 125 #else
124 static void SignalHandler(int) 126 static void SignalHandler(int signal)
125 { 127 {
126 finish = true; 128 if (signal == SIGHUP)
129 {
130 barrierEvent_ = ServerBarrierEvent_Reload;
131 }
132
133 finish_ = true;
127 } 134 }
128 #endif 135 #endif
129 136
130 137
131 void Toolbox::USleep(uint64_t microSeconds) 138 void Toolbox::USleep(uint64_t microSeconds)
138 #error Support your platform here 145 #error Support your platform here
139 #endif 146 #endif
140 } 147 }
141 148
142 149
143 static void ServerBarrierInternal(const bool* stopFlag) 150 static ServerBarrierEvent ServerBarrierInternal(const bool* stopFlag)
144 { 151 {
145 #if defined(_WIN32) 152 #if defined(_WIN32)
146 SetConsoleCtrlHandler(ConsoleControlHandler, true); 153 SetConsoleCtrlHandler(ConsoleControlHandler, true);
147 #else 154 #else
148 signal(SIGINT, SignalHandler); 155 signal(SIGINT, SignalHandler);
149 signal(SIGQUIT, SignalHandler); 156 signal(SIGQUIT, SignalHandler);
150 signal(SIGTERM, SignalHandler); 157 signal(SIGTERM, SignalHandler);
158 signal(SIGHUP, SignalHandler);
151 #endif 159 #endif
152 160
153 // Active loop that awakens every 100ms 161 // Active loop that awakens every 100ms
154 finish = false; 162 finish_ = false;
155 while (!(*stopFlag || finish)) 163 barrierEvent_ = ServerBarrierEvent_Stop;
164 while (!(*stopFlag || finish_))
156 { 165 {
157 Toolbox::USleep(100 * 1000); 166 Toolbox::USleep(100 * 1000);
158 } 167 }
159 168
160 #if defined(_WIN32) 169 #if defined(_WIN32)
161 SetConsoleCtrlHandler(ConsoleControlHandler, false); 170 SetConsoleCtrlHandler(ConsoleControlHandler, false);
162 #else 171 #else
163 signal(SIGINT, NULL); 172 signal(SIGINT, NULL);
164 signal(SIGQUIT, NULL); 173 signal(SIGQUIT, NULL);
165 signal(SIGTERM, NULL); 174 signal(SIGTERM, NULL);
166 #endif 175 signal(SIGHUP, NULL);
167 } 176 #endif
168 177
169 178 return barrierEvent_;
170 void Toolbox::ServerBarrier(const bool& stopFlag) 179 }
171 { 180
172 ServerBarrierInternal(&stopFlag); 181
173 } 182 ServerBarrierEvent Toolbox::ServerBarrier(const bool& stopFlag)
174 183 {
175 void Toolbox::ServerBarrier() 184 return ServerBarrierInternal(&stopFlag);
185 }
186
187 ServerBarrierEvent Toolbox::ServerBarrier()
176 { 188 {
177 const bool stopFlag = false; 189 const bool stopFlag = false;
178 ServerBarrierInternal(&stopFlag); 190 return ServerBarrierInternal(&stopFlag);
179 } 191 }
180 192
181 193
182 void Toolbox::ToUpperCase(std::string& s) 194 void Toolbox::ToUpperCase(std::string& s)
183 { 195 {