Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions CCDB/include/CCDB/CCDBDownloader.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// Copyright 2019-2023 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
Expand All @@ -8,10 +8,11 @@
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#ifndef O2_CCDBDOWNLOADER_H_
#define O2_CCDBDOWNLOADER_H_

#include <cstdio>
#include <cstdlib>
#include <uv.h>
#include <curl/curl.h>
#include <string>
#include <vector>
Expand All @@ -21,14 +22,16 @@
#include <condition_variable>
#include <unordered_map>

#ifndef ALICEO2_CCDBDOWNLOADER_H
#define ALICEO2_CCDBDOWNLOADER_H
typedef struct uv_loop_s uv_loop_t;
typedef struct uv_timer_s uv_timer_t;
typedef struct uv_poll_s uv_poll_t;
typedef struct uv_signal_s uv_signal_t;
typedef struct uv_async_s uv_async_t;
typedef struct uv_handle_s uv_handle_t;

using namespace std;

namespace o2
{
namespace ccdb
namespace o2::ccdb
{

/*
Expand Down Expand Up @@ -195,7 +198,7 @@ class CCDBDownloader
* Information about a socket.
*/
typedef struct curl_context_s {
uv_poll_t poll_handle;
uv_poll_t* poll_handle;
curl_socket_t sockfd = -1;
CCDBDownloader* CD = nullptr;
} curl_context_t;
Expand Down Expand Up @@ -355,7 +358,6 @@ typedef struct DataForClosingSocket {
curl_socket_t socket;
} DataForClosingSocket;

} // namespace ccdb
} // namespace o2

#endif
#endif // O2_CCDB_CCDBDOWNLOADER_H
25 changes: 13 additions & 12 deletions CCDB/src/CCDBDownloader.cxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// Copyright 2019-2023 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
Expand All @@ -12,6 +12,8 @@
#include <CCDB/CCDBDownloader.h>

#include <curl/curl.h>
#include <uv.h>

#include <unordered_map>
#include <cstdio>
#include <cstdlib>
Expand All @@ -25,9 +27,7 @@
#include <sys/types.h>
#include <sys/socket.h>

namespace o2
{
namespace ccdb
namespace o2::ccdb
{

CCDBDownloader::CCDBDownloader(uv_loop_t* uv_loop)
Expand Down Expand Up @@ -229,14 +229,14 @@ int CCDBDownloader::handleSocket(CURL* easy, curl_socket_t s, int action, void*
uv_timer_stop(CD->mSocketTimerMap[s]);
}

uv_poll_start(&curl_context->poll_handle, events, curlPerform);
uv_poll_start(curl_context->poll_handle, events, curlPerform);
break;
case CURL_POLL_REMOVE:
if (socketp) {
if (CD->mSocketTimerMap.find(s) != CD->mSocketTimerMap.end()) {
uv_timer_start(CD->mSocketTimerMap[s], closeSocketByTimer, CD->mSocketTimeoutMS, 0);
}
uv_poll_stop(&((CCDBDownloader::curl_context_t*)socketp)->poll_handle);
uv_poll_stop(((CCDBDownloader::curl_context_t*)socketp)->poll_handle);
CD->destroyCurlContext((CCDBDownloader::curl_context_t*)socketp);
curl_multi_assign(socketData->curlm, s, nullptr);
}
Expand Down Expand Up @@ -277,23 +277,25 @@ CCDBDownloader::curl_context_t* CCDBDownloader::createCurlContext(curl_socket_t
context = (curl_context_t*)malloc(sizeof(*context));
context->CD = this;
context->sockfd = sockfd;
context->poll_handle = new uv_poll_t();

uv_poll_init_socket(mUVLoop, &context->poll_handle, sockfd);
mHandleMap[(uv_handle_t*)(&context->poll_handle)] = true;
context->poll_handle.data = context;
uv_poll_init_socket(mUVLoop, context->poll_handle, sockfd);
mHandleMap[(uv_handle_t*)(context->poll_handle)] = true;
context->poll_handle->data = context;

return context;
}

void CCDBDownloader::curlCloseCB(uv_handle_t* handle)
{
curl_context_t* context = (curl_context_t*)handle->data;
auto* context = (curl_context_t*)handle->data;
delete context->poll_handle;
free(context);
}

void CCDBDownloader::destroyCurlContext(curl_context_t* context)
{
uv_close((uv_handle_t*)&context->poll_handle, curlCloseCB);
uv_close((uv_handle_t*)context->poll_handle, curlCloseCB);
}

void callbackWrappingFunction(void (*cbFun)(void*), void* data, bool* completionFlag)
Expand Down Expand Up @@ -498,5 +500,4 @@ void CCDBDownloader::makeLoopCheckQueueAsync()
uv_async_send(asyncHandle);
}

} // namespace ccdb
} // namespace o2
1 change: 1 addition & 0 deletions CCDB/test/testCcdbApiDownloader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <boost/test/unit_test.hpp>
#include <boost/optional/optional.hpp>
#include <uv.h>

using namespace std;

Expand Down