bes  Updated for version 3.20.6
CurlHandlePool.h
1 // -*- mode: c++; c-basic-offset:4 -*-
2 
3 // This file is part of the BES
4 
5 // Copyright (c) 2018 OPeNDAP, Inc.
6 // Author: James Gallagher<jgallagher@opendap.org>
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 //
22 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
23 
24 #ifndef _HandlePool_h
25 #define _HandlePool_h 1
26 
27 #include <string>
28 #include <vector>
29 
30 #include <pthread.h>
31 
32 #include <curl/curl.h>
33 
34 namespace dmrpp {
35 
36 class Chunk;
37 
41 class Lock {
42 private:
43  pthread_mutex_t& m_mutex;
44 
45  Lock();
46  Lock(const Lock &rhs);
47 
48 public:
49  Lock(pthread_mutex_t &lock);
50  virtual ~Lock();
51 };
52 
62  bool d_in_use;
63  std::string d_url;
64  Chunk *d_chunk;
65  char d_errbuf[CURL_ERROR_SIZE];
66  CURL *d_handle;
67  struct curl_slist *d_headers;
68 
69  friend class CurlHandlePool;
70  friend class dmrpp_multi_handle;
71 
72 public:
75 
76  void read_data();
77 };
78 
79 
84  // This struct can be a vector<dmrpp_easy_handle*> or a CURLM *, depending
85  // on whether the curl lib support the Multi API. ...commonly known as the
86  // 'pointer to an implementation' pattern which has the unfortunate acronym
87  // 'pimpl.' jhrg 8/27/18
88  struct multi_handle;
89 
90  multi_handle *p_impl;
91 
92 public:
94 
96 
98 
99  void read_data();
100 };
101 
115 private:
116  unsigned int d_max_easy_handles;
117 
118  std::vector<dmrpp_easy_handle *> d_easy_handles;
119 
120  dmrpp_multi_handle *d_multi_handle;
121 
122  pthread_mutex_t d_get_easy_handle_mutex;
123 
124  friend class Lock;
125 
126 public:
127  CurlHandlePool();
128 
129  ~CurlHandlePool()
130  {
131 #if 1
132  for (std::vector<dmrpp_easy_handle *>::iterator i = d_easy_handles.begin(), e = d_easy_handles.end();
133  i != e; ++i) {
134  delete *i;
135  }
136 #else
137  for (auto &d_easy_handle: d_easy_handles) {
138  delete d_easy_handle;
139  }
140 #endif
141  delete d_multi_handle;
142  }
143 
144  unsigned int get_max_handles() const
145  {
146  return d_max_easy_handles;
147  }
148 
149  dmrpp_multi_handle *get_multi_handle()
150  {
151  return d_multi_handle;
152  }
153 
155 
157 };
158 
159 } // namespace dmrpp
160 
161 #endif // _HandlePool_h
dmrpp::Chunk
Definition: Chunk.h:43
dmrpp::dmrpp_easy_handle
Bundle a libcurl easy handle to other information.
Definition: CurlHandlePool.h:61
dmrpp::dmrpp_easy_handle::read_data
void read_data()
This is the read_data() method for serial transfers.
Definition: CurlHandlePool.cc:313
dmrpp::dmrpp_easy_handle::dmrpp_easy_handle
dmrpp_easy_handle()
Build a string with hex info about stuff libcurl gets.
Definition: CurlHandlePool.cc:218
dmrpp::dmrpp_multi_handle::read_data
void read_data()
The read_data() method for parallel transfers.
Definition: CurlHandlePool.cc:439
dmrpp::dmrpp_multi_handle
Encapsulate a libcurl multi handle.
Definition: CurlHandlePool.h:83
dmrpp::dmrpp_multi_handle::add_easy_handle
void add_easy_handle(dmrpp_easy_handle *eh)
Add an Easy Handle to a Multi Handle object.
Definition: CurlHandlePool.cc:400
dmrpp::CurlHandlePool::get_easy_handle
dmrpp_easy_handle * get_easy_handle(Chunk *chunk)
Definition: CurlHandlePool.cc:768
dmrpp::Lock
Definition: CurlHandlePool.h:41
dmrpp::CurlHandlePool
Definition: CurlHandlePool.h:114
dmrpp::CurlHandlePool::release_handle
void release_handle(dmrpp_easy_handle *h)
Definition: CurlHandlePool.cc:869