| 248 | } |
| 249 | |
| 250 | void HttpService::abortJob(HttpJobId jobId) |
| 251 | { |
| 252 | MutexGuard<Mutex> guard(m_mutex); |
| 253 | |
| 254 | if (true == m_isRunning) |
| 255 | { |
| 256 | bool isAborted = false; |
| 257 | |
| 258 | /* Is in the pending request queue? */ |
| 259 | for (auto it = m_requestList.begin(); it != m_requestList.end(); ++it) |
| 260 | { |
| 261 | if (jobId == it->jobId) |
| 262 | { |
| 263 | /* Remove the request from the list. */ |
| 264 | (void)m_requestList.erase(it); |
| 265 | isAborted = true; |
| 266 | break; |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | if (false == isAborted) |
| 271 | { |
| 272 | /* Is it the currently active job? */ |
| 273 | if (jobId == m_activeJobId) |
| 274 | { |
| 275 | HttpJobId abortedJobId = INVALID_HTTP_JOB_ID; |
| 276 | |
| 277 | (void)m_workerData.mutex.take(portMAX_DELAY); |
| 278 | m_workerData.jobToAbort = jobId; |
| 279 | (void)m_workerData.mutex.give(); |
| 280 | |
| 281 | /* Wait till the job is aborted. */ |
| 282 | while (1) |
| 283 | { |
| 284 | if (true == m_workerData.mutex.take(0U)) |
| 285 | { |
| 286 | /* Aborted? */ |
| 287 | if (INVALID_HTTP_JOB_ID != m_workerData.abortedJob) |
| 288 | { |
| 289 | isAborted = true; |
| 290 | m_workerData.abortedJob = INVALID_HTTP_JOB_ID; |
| 291 | (void)m_workerData.mutex.give(); |
| 292 | break; |
| 293 | } |
| 294 | /* No pending job anymore? */ |
| 295 | if (INVALID_HTTP_JOB_ID == m_workerData.jobToAbort) |
| 296 | { |
| 297 | m_activeJobId = INVALID_HTTP_JOB_ID; |
| 298 | (void)m_workerData.mutex.give(); |
| 299 | break; |
| 300 | } |
| 301 | /* Wait until worker aborted the job. */ |
| 302 | else |
| 303 | { |
| 304 | (void)m_workerData.mutex.give(); |
| 305 | delay(1U); |
| 306 | } |
| 307 | } |