Skip to content

Commit

Permalink
enable http connection resuse
Browse files Browse the repository at this point in the history
  • Loading branch information
huangminghuang committed Nov 4, 2022
1 parent 728faf5 commit 06c9e25
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Requirements to build:
- newer versions do not work
- openssl 1.1+
- curl
- libcurl 7.40.0+
- git
- GMP
- Python 3
Expand All @@ -70,7 +71,7 @@ git clone --recursive https://github.com/AntelopeIO/leap.git
git clone --recursive git@github.com:AntelopeIO/leap.git
```

> ℹ️ **HTTPS vs. SSH Clone** ℹ️
> ℹ️ **HTTPS vs. SSH Clone** ℹ️
Both an HTTPS or SSH git clone will yield the same result - a folder named `leap` containing our source code. It doesn't matter which type you use.

Navigate into that folder:
Expand All @@ -94,13 +95,13 @@ git submodule update --init --recursive
### Step 3 - Build
Select build instructions below for a [pinned build](#pinned-build) (preferred) or an [unpinned build](#unpinned-build).

> ℹ️ **Pinned vs. Unpinned Build** ℹ️
> ℹ️ **Pinned vs. Unpinned Build** ℹ️
We have two types of builds for Leap: "pinned" and "unpinned." The only difference is that pinned builds use specific versions for some dependencies hand-picked by the Leap engineers - they are "pinned" to those versions. In contrast, unpinned builds use the default dependency versions available on the build system at the time. We recommend performing a "pinned" build to ensure the compiler and boost versions remain the same between builds of different Leap versions. Leap requires these versions to remain the same, otherwise its state might need to be recovered from a portable snapshot or the chain needs to be replayed.

> ⚠️ **A Warning On Parallel Compilation Jobs (`-j` flag)** ⚠️
> ⚠️ **A Warning On Parallel Compilation Jobs (`-j` flag)** ⚠️
When building C/C++ software, often the build is performed in parallel via a command such as `make -j "$(nproc)"` which uses all available CPU threads. However, be aware that some compilation units (`*.cpp` files) in Leap will consume nearly 4GB of memory. Failures due to memory exhaustion will typically, but not always, manifest as compiler crashes. Using all available CPU threads may also prevent you from doing other things on your computer during compilation. For these reasons, consider reducing this value.

> πŸ‹ **Docker and `sudo`** πŸ‹
> πŸ‹ **Docker and `sudo`** πŸ‹
If you are in an Ubuntu docker container, omit `sudo` from all commands because you run as `root` by default. Most other docker containers also exclude `sudo`, especially Debian-family containers. If your shell prompt is a hash tag (`#`), omit `sudo`.

#### Pinned Build
Expand Down
14 changes: 9 additions & 5 deletions programs/cleos/do_http_post_libcurl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "do_http_post.hpp"
#include <curl/curl.h>
#include <eosio/chain/exceptions.hpp>
#include <fc/scoped_exit.hpp>
#include <map>

namespace eosio { namespace client { namespace http {

Expand Down Expand Up @@ -65,6 +65,11 @@ namespace eosio { namespace client { namespace http {
return 0;
}

struct curl_handle : std::unique_ptr<CURL, decltype(&curl_easy_cleanup)> {
curl_handle(int) : std::unique_ptr<CURL, decltype(&curl_easy_cleanup)>( curl_easy_init(), &curl_easy_cleanup) {}
};


std::tuple<unsigned int, std::string> do_http_post(const std::string& base_uri, const std::string& path,
const std::vector<std::string>& headers,
const std::string& postjson, bool verify_cert, bool verbose,
Expand All @@ -78,11 +83,10 @@ namespace eosio { namespace client { namespace http {
initialized = true;
}

auto curl = curl_easy_init();
static std::map<std::string, curl_handle> handles;
auto [itr, _] = handles.emplace(base_uri, 0);
auto curl = itr->second.get();
EOS_ASSERT(curl != 0, chain::http_exception, "curl_easy_init failed");
auto on_exit = fc::make_scoped_exit([curl]() {
curl_easy_cleanup(curl);
});

std::string uri;

Expand Down

0 comments on commit 06c9e25

Please sign in to comment.