Continued from here: Pool of curl handlesThis is my second attempt. Improvements include 1) cannot copy connection, 2) connection doesn't leak CURL* pointer 2) closed connections release the handleclass curl_pool{private:    uint               m_size;    queue<uint>        m_queue;    std::vector<CURL*> m_handles;public:    class connection    {        friend class curl_pool;    private:        curl_pool &m_pool;        int        m_index;        connection(curl_pool &pool, uint index) : m_pool(pool), m_index(index) {}        connection(connection const &that) = delete;        void operator=(connection const &that) = delete;    public:        connection(connection&& that) : m_pool(that.m_pool), m_index(that.m_index) {}        bool is_open() {            return m_index >= 0;        }        void release() {            if (is_open()) {                m_pool.m_queue.push((uint) m_index);                m_index = -1;            }        }        void set_url(std::string const &url) {            if (is_open()) {                curl_easy_setopt(m_pool.m_handles[m_index],                                 CURLOPT_URL,                                 url.c_str());            }        }        long perform() {            long code = -1;            if (is_open()) {                curl_easy_perform(m_pool.m_handles[m_index]);                curl_easy_getinfo(m_pool.m_handles[m_index],                                   CURLINFO_RESPONSE_CODE,                                   &code);            }            return code;        }        virtual ~connection() {            if (is_open()) {                release();            }        }    };    connection open() {        return connection(*this, m_queue.pop());    }    curl_pool(const std::string &root_cert, uint size) : m_size(size) {        curl_global_init(CURL_GLOBAL_DEFAULT);        m_handles.reserve(m_size);        for (uint i = 0; i < m_size; i++) {            CURL *curl = curl_easy_init();            curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);            curl_easy_setopt(curl, CURLOPT_CAINFO, root_cert.c_str());            curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);            curl_easy_setopt(curl, CURLOPT_TCP_KEEPIDLE, 120L);            curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);            m_handles[i] = curl;            m_queue.push(i);        }    }    virtual ~curl_pool() {        for (int i = 0; i < m_size; i++) {            curl_easy_cleanup(m_handles[i]);        }        curl_global_cleanup();    }};This is the intended use:{    curl_pool::connection c = pool.open();    c.set_url(https://google.com);    long code = c.perform();    stream << Response code:  << code;}
Pool of curl handles (Take 2)
c++;c++11;curl;connection pool