bes  Updated for version 3.20.5
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 
68  friend class CurlHandlePool;
69  friend class dmrpp_multi_handle;
70 
71 public:
74 
75  void read_data();
76 };
77 
78 
83  // This struct can be a vector<dmrpp_easy_handle*> or a CURLM *, depending
84  // on whether the curl lib support the Multi API. ...commonly known as the
85  // 'pointer to an implementation' pattern which has the unfortunate acronym
86  // 'pimpl.' jhrg 8/27/18
87  struct multi_handle;
88 
89  multi_handle *p_impl;
90 
91 public:
93 
95 
97 
98  void read_data();
99 };
100 
114 private:
115  unsigned int d_max_easy_handles;
116 
117  std::vector<dmrpp_easy_handle *> d_easy_handles;
118 
119  dmrpp_multi_handle *d_multi_handle;
120 
121  pthread_mutex_t d_get_easy_handle_mutex;
122 
123  friend class Lock;
124 
125 public:
126  CurlHandlePool();
127 
128  ~CurlHandlePool()
129  {
130  for (std::vector<dmrpp_easy_handle *>::iterator i = d_easy_handles.begin(), e = d_easy_handles.end(); i != e; ++i) {
131  delete *i;
132  }
133 
134  delete d_multi_handle;
135  }
136 
137  unsigned int get_max_handles() const
138  {
139  return d_max_easy_handles;
140  }
141 
142  dmrpp_multi_handle *get_multi_handle()
143  {
144  return d_multi_handle;
145  }
146 
148 
150 };
151 
152 } // namespace dmrpp
153 
154 #endif // _HandlePool_h
void read_data()
This is the read_data() method for serial transfers.
dmrpp_easy_handle()
Build a string with hex info about stuff libcurl gets.
Bundle a libcurl easy handle to other information.
Encapsulate a libcurl multi handle.
dmrpp_easy_handle * get_easy_handle(Chunk *chunk)
void read_data()
The read_data() method for parallel transfers.
void release_handle(dmrpp_easy_handle *h)
void add_easy_handle(dmrpp_easy_handle *eh)
Add an Easy Handle to a Multi Handle object.