| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,21 +38,12 @@ namespace session { | |||
| 38 | 38 | ||
| 39 | 39 | namespace { | |
| 40 | 40 | ||
| 41 | - const int kLastChanceWaitSecs = 4; | ||
| 42 | - | ||
| 43 | 41 | bool hasEventIdLessThanOrEqualTo(const json::Value& event, int targetId) | |
| 44 | 42 | { | |
| 45 | 43 | const json::Object& eventJSON = event.get_obj(); | |
| 46 | 44 | int eventId = eventJSON.find("id")->second.get_int(); | |
| 47 | 45 | return eventId <= targetId; | |
| 48 | 46 | } | |
| 49 | - | ||
| 50 | - boost::shared_ptr<HttpConnection> waitForConnection(int seconds) | ||
| 51 | - { | ||
| 52 | - return httpConnectionListener().eventsConnectionQueue().dequeConnection( | ||
| 53 | - boost::posix_time::seconds(seconds)); | ||
| 54 | - } | ||
| 55 | - | ||
| 56 | 47 | ||
| 57 | 48 | } // anonymous namespace | |
| 58 | 49 | ||
@@ -97,11 +88,10 @@ void ClientEventService::stop() | |||
| 97 | 88 | { | |
| 98 | 89 | serviceThread_.interrupt(); | |
| 99 | 90 | ||
| 100 | - // wait forthe service thread to stop | ||
| 101 | - if (!serviceThread_.timed_join( | ||
| 102 | - boost::posix_time::seconds(kLastChanceWaitSecs + 1))) | ||
| 91 | + // wait for up to 3 seconds for the service thread to stop | ||
| 92 | + if (!serviceThread_.timed_join(boost::posix_time::seconds(3))) | ||
| 103 | 93 | { | |
| 104 | - LOG_WARNING_MESSAGE("ClientEventService didn't stop"); | ||
| 94 | + LOG_WARNING_MESSAGE("ClientEventService didn't stop within 3 sec"); | ||
| 105 | 95 | } | |
| 106 | 96 | ||
| 107 | 97 | serviceThread_.detach(); | |
@@ -219,45 +209,26 @@ void ClientEventService::run() | |||
| 219 | 209 | try | |
| 220 | 210 | { | |
| 221 | 211 | // wait for up to 1 second for a connection | |
| 222 | - ptrConnection = waitForConnection(1); | ||
| 212 | + ptrConnection = | ||
| 213 | + httpConnectionListener().eventsConnectionQueue().dequeConnection( | ||
| 214 | + boost::posix_time::seconds(1)); | ||
| 223 | 215 | ||
| 224 | 216 | // if we didn't get one then check for interruption requested | |
| 225 | 217 | // and then continue waiting | |
| 226 | 218 | if (!ptrConnection) | |
| 227 | 219 | { | |
| 228 | 220 | // check for interruption and set stopServer flag if we were | |
| 229 | 221 | if (boost::this_thread::interruption_requested()) | |
| 230 | - { | ||
| 231 | 222 | stopServer = true; | |
| 232 | 223 | ||
| 233 | - // last chance listen | ||
| 234 | - if (clientEventQueue.hasEvents()) | ||
| 235 | - ptrConnection = waitForConnection(kLastChanceWaitSecs); | ||
| 236 | - | ||
| 237 | - if (!ptrConnection) | ||
| 238 | - continue; | ||
| 239 | - } | ||
| 240 | - else | ||
| 241 | - { | ||
| 242 | - // accept next request | ||
| 243 | - continue; | ||
| 244 | - } | ||
| 224 | + // accept next request (assuming we weren't interrupted) | ||
| 225 | + continue; | ||
| 245 | 226 | } | |
| 246 | 227 | } | |
| 247 | 228 | catch(const boost::thread_interrupted&) | |
| 248 | 229 | { | |
| 249 | - if (stopServer) | ||
| 250 | - continue; | ||
| 251 | - | ||
| 252 | 230 | stopServer = true; | |
| 253 | - | ||
| 254 | - // last chance listen (no try catch to keep code simpler - | ||
| 255 | - // we would never interrupt the thread twice) | ||
| 256 | - if (clientEventQueue.hasEvents()) | ||
| 257 | - ptrConnection = waitForConnection(kLastChanceWaitSecs); | ||
| 258 | - | ||
| 259 | - if (!ptrConnection) | ||
| 260 | - continue; | ||
| 231 | + continue; | ||
| 261 | 232 | } | |
| 262 | 233 | ||
| 263 | 234 | // parse the json rpc request | |
| Back | FazBrowse Home | New Git URL |
0 commit comments