|
1 | | -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. |
| 1 | +// Copyright 2019-2023 CERN and copyright holders of ALICE O2. |
2 | 2 | // See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
3 | 3 | // All rights not expressly granted are reserved. |
4 | 4 | // |
|
12 | 12 | #include <CCDB/CCDBDownloader.h> |
13 | 13 |
|
14 | 14 | #include <curl/curl.h> |
| 15 | +#include <uv.h> |
| 16 | + |
15 | 17 | #include <unordered_map> |
16 | 18 | #include <cstdio> |
17 | 19 | #include <cstdlib> |
|
25 | 27 | #include <sys/types.h> |
26 | 28 | #include <sys/socket.h> |
27 | 29 |
|
28 | | -namespace o2 |
29 | | -{ |
30 | | -namespace ccdb |
| 30 | +namespace o2::ccdb |
31 | 31 | { |
32 | 32 |
|
33 | 33 | CCDBDownloader::CCDBDownloader(uv_loop_t* uv_loop) |
@@ -229,14 +229,14 @@ int CCDBDownloader::handleSocket(CURL* easy, curl_socket_t s, int action, void* |
229 | 229 | uv_timer_stop(CD->mSocketTimerMap[s]); |
230 | 230 | } |
231 | 231 |
|
232 | | - uv_poll_start(&curl_context->poll_handle, events, curlPerform); |
| 232 | + uv_poll_start(curl_context->poll_handle, events, curlPerform); |
233 | 233 | break; |
234 | 234 | case CURL_POLL_REMOVE: |
235 | 235 | if (socketp) { |
236 | 236 | if (CD->mSocketTimerMap.find(s) != CD->mSocketTimerMap.end()) { |
237 | 237 | uv_timer_start(CD->mSocketTimerMap[s], closeSocketByTimer, CD->mSocketTimeoutMS, 0); |
238 | 238 | } |
239 | | - uv_poll_stop(&((CCDBDownloader::curl_context_t*)socketp)->poll_handle); |
| 239 | + uv_poll_stop(((CCDBDownloader::curl_context_t*)socketp)->poll_handle); |
240 | 240 | CD->destroyCurlContext((CCDBDownloader::curl_context_t*)socketp); |
241 | 241 | curl_multi_assign(socketData->curlm, s, nullptr); |
242 | 242 | } |
@@ -277,23 +277,25 @@ CCDBDownloader::curl_context_t* CCDBDownloader::createCurlContext(curl_socket_t |
277 | 277 | context = (curl_context_t*)malloc(sizeof(*context)); |
278 | 278 | context->CD = this; |
279 | 279 | context->sockfd = sockfd; |
| 280 | + context->poll_handle = new uv_poll_t(); |
280 | 281 |
|
281 | | - uv_poll_init_socket(mUVLoop, &context->poll_handle, sockfd); |
282 | | - mHandleMap[(uv_handle_t*)(&context->poll_handle)] = true; |
283 | | - context->poll_handle.data = context; |
| 282 | + uv_poll_init_socket(mUVLoop, context->poll_handle, sockfd); |
| 283 | + mHandleMap[(uv_handle_t*)(context->poll_handle)] = true; |
| 284 | + context->poll_handle->data = context; |
284 | 285 |
|
285 | 286 | return context; |
286 | 287 | } |
287 | 288 |
|
288 | 289 | void CCDBDownloader::curlCloseCB(uv_handle_t* handle) |
289 | 290 | { |
290 | | - curl_context_t* context = (curl_context_t*)handle->data; |
| 291 | + auto* context = (curl_context_t*)handle->data; |
| 292 | + delete context->poll_handle; |
291 | 293 | free(context); |
292 | 294 | } |
293 | 295 |
|
294 | 296 | void CCDBDownloader::destroyCurlContext(curl_context_t* context) |
295 | 297 | { |
296 | | - uv_close((uv_handle_t*)&context->poll_handle, curlCloseCB); |
| 298 | + uv_close((uv_handle_t*)context->poll_handle, curlCloseCB); |
297 | 299 | } |
298 | 300 |
|
299 | 301 | void callbackWrappingFunction(void (*cbFun)(void*), void* data, bool* completionFlag) |
@@ -498,5 +500,4 @@ void CCDBDownloader::makeLoopCheckQueueAsync() |
498 | 500 | uv_async_send(asyncHandle); |
499 | 501 | } |
500 | 502 |
|
501 | | -} // namespace ccdb |
502 | 503 | } // namespace o2 |
0 commit comments