Skip to content

Commit

Permalink
Updated curl websockets as unique_ptr.
Browse files Browse the repository at this point in the history
████ ███  To request new features or in case this commit breaks something for you,
████ ███  please, create a new github issue with all possible information for me,
▓███▀█▄   but never share your API Keys!
▒▓██ ███
░▒▓█ ███  Signed-off-by: Carles Tubio <[email protected]>
 _________________________________________
/ Hello, WORLD!                           \
|                                         |
\ pssst.. 1.00000000 BTC = 58834.79 EUR.  /
 -----------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
  • Loading branch information
ctubio committed Sep 28, 2024
1 parent 6d6f3ca commit 49238d3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ K ?= K.sh
MAJOR = 0
MINOR = 7
PATCH = 0
BUILD = 19
BUILD = 20

OBLIGATORY = DISCLAIMER: This is strict non-violent software: \n$\
if you hurt other living creatures, please stop; \n$\
Expand Down
36 changes: 18 additions & 18 deletions src/lib/Krypto.ninja-data.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,19 +456,19 @@ namespace ₿ {
string in;
private:
string out;
CURL *curl = nullptr;
unique_ptr<CURL, decltype(&curl_easy_cleanup)> curl;
private_ref:
mutex *const &lock;
public:
Easy(mutex *const &l)
: lock(l)
: curl(nullptr, curl_easy_cleanup)
, lock(l)
{};
protected:
void cleanup() {
if (curl) {
if (!out.empty()) send();
curl_easy_cleanup(curl);
curl = nullptr;
curl.reset();
stop();
}
};
Expand All @@ -481,12 +481,12 @@ namespace ₿ {
in.clear();
CURLcode rc;
if (CURLE_OK == (rc = init())) {
args_easy_setopt(curl);
curl_easy_setopt(curl, CURLOPT_URL, url.data());
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
if ( CURLE_OK != (rc = curl_easy_perform(curl))
or CURLE_OK != (rc = curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sockfd))
args_easy_setopt(curl.get());
curl_easy_setopt(curl.get(), CURLOPT_URL, url.data());
curl_easy_setopt(curl.get(), CURLOPT_NOSIGNAL, 1L);
curl_easy_setopt(curl.get(), CURLOPT_CONNECT_ONLY, 1L);
if ( CURLE_OK != (rc = curl_easy_perform(curl.get()))
or CURLE_OK != (rc = curl_easy_getinfo(curl.get(), CURLINFO_ACTIVESOCKET, &sockfd))
or CURLE_OK != (rc = send())
or CURLE_OK != (rc = recv(5))
or string::npos == in.find(res1)
Expand Down Expand Up @@ -529,8 +529,8 @@ namespace ₿ {
};
private:
CURLcode init() {
if (!curl) curl = curl_easy_init();
else curl_easy_reset(curl);
if (!curl) curl.reset(curl_easy_init());
else curl_easy_reset(curl.get());
sockfd = 0;
return curl
? CURLE_OK
Expand All @@ -541,7 +541,7 @@ namespace ₿ {
do {
do {
size_t n = 0;
rc = curl_easy_send(curl, out.data(), out.length(), &n);
rc = curl_easy_send(curl.get(), out.data(), out.length(), &n);
out = out.substr(n);
if (rc == CURLE_AGAIN and !wait(false, 5))
return CURLE_OPERATION_TIMEDOUT;
Expand All @@ -558,7 +558,7 @@ namespace ₿ {
size_t n;
do {
n = 0;
rc = curl_easy_recv(curl, data, sizeof(data), &n);
rc = curl_easy_recv(curl.get(), data, sizeof(data), &n);
#ifdef _WIN32
if (rc == CURLE_UNSUPPORTED_PROTOCOL and n == 0)
rc = CURLE_OK;
Expand Down Expand Up @@ -920,7 +920,7 @@ namespace ₿ {
Socket::start(loopfd, ioHttp);
};
void shutdown() {
ssl.release();
ssl.reset();
Socket::shutdown();
if (!time) session->upgrade(-1, addr);
};
Expand Down Expand Up @@ -1119,7 +1119,7 @@ namespace ₿ {
requests.back().shutdown();
requests.pop_back();
}
ctx.release();
ctx.reset();
shutdown();
};
void timeouts() {
Expand Down Expand Up @@ -1223,7 +1223,7 @@ namespace ₿ {
);
if (!SSL_CTX_use_certificate(ctx.get(), cert.get())
or !SSL_CTX_use_PrivateKey(ctx.get(), pkey.get())
) ctx.release();
) ctx.reset();
} else {
if (access(crt.data(), R_OK) == -1)
warn.emplace_back("Unable to read SSL .crt file at " + crt);
Expand All @@ -1232,7 +1232,7 @@ namespace ₿ {
if (!SSL_CTX_use_certificate_file(ctx.get(), crt.data(), SSL_FILETYPE_PEM)
or !SSL_CTX_use_PrivateKey_file(ctx.get(), key.data(), SSL_FILETYPE_PEM)
) {
ctx.release();
ctx.reset();
warn.emplace_back("Unable to encrypt web clients using the .crt and .key files, will fallback to plain text");
}
}
Expand Down

0 comments on commit 49238d3

Please sign in to comment.