libzypp  17.31.31
networkrequestdispatcher_p.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 ----------------------------------------------------------------------/
9 *
10 * This file contains private API, this might break at any time between releases.
11 * You have been warned!
12 *
13 */
14 #ifndef ZYPP_NG_MEDIA_CURL_PRIVATE_CURL_P_H_INCLUDED
15 #define ZYPP_NG_MEDIA_CURL_PRIVATE_CURL_P_H_INCLUDED
16 
18 #include <zypp-core/zyppng/base/private/base_p.h>
19 #include <curl/curl.h>
20 #include <deque>
21 #include <set>
22 #include <unordered_map>
23 
24 namespace zyppng {
25 
26 class Timer;
27 class SocketNotifier;
28 
30 {
31  ZYPP_DECLARE_PUBLIC(NetworkRequestDispatcher)
32 public:
33  NetworkRequestDispatcherPrivate ( NetworkRequestDispatcher &p );
35 
36  int _maxConnections = 10;
37 
38  std::deque< std::shared_ptr<NetworkRequest> > _pendingDownloads;
39  std::vector< std::shared_ptr<NetworkRequest> > _runningDownloads;
40 
41  std::shared_ptr<Timer> _timer;
42  std::map< curl_socket_t, std::shared_ptr<SocketNotifier> > _socketHandler;
43 
44  bool _isRunning = false;
45  bool _locked = false; //if set to true, no new requests will be dequeued
46  CURLM *_multi = nullptr;
47 
49 
50  std::string _userAgent;
51  std::unordered_map< std::string, std::unordered_map<std::string, std::string> > _customHeaders;
52 
53  //signals
54  Signal< void ( NetworkRequestDispatcher &, NetworkRequest & )> _sigDownloadStarted;
55  Signal< void ( NetworkRequestDispatcher &, NetworkRequest & )> _sigDownloadFinished;
56  Signal< void ( NetworkRequestDispatcher & )> _sigQueueFinished;
57  Signal< void ( NetworkRequestDispatcher & )> _sigError;
58 
59 private:
60  static int multi_timer_cb ( CURLM *multi, long timeout_ms, void *g );
61  static int static_socket_callback(CURL *easy, curl_socket_t s, int what, void *userp, SocketNotifier *socketp );
62 
63  void multiTimerTimout ( const Timer &t );
64  int socketCallback(CURL *easy, curl_socket_t s, int what, void * );
65 
66  void cancelAll ( NetworkRequestError result );
68  void setFinished( NetworkRequest &req , NetworkRequestError result );
69 
70  void onSocketActivated ( const SocketNotifier &listener, int events );
71 
72  void handleMultiSocketAction ( curl_socket_t nativeSocket, int evBitmask );
73  void dequeuePending ();
74 };
75 }
76 
77 #endif
static int multi_timer_cb(CURLM *multi, long timeout_ms, void *g)
void cancelAll(NetworkRequestError result)
int socketCallback(CURL *easy, curl_socket_t s, int what, void *)
NetworkRequestDispatcherPrivate(NetworkRequestDispatcher &p)
Signal< void(NetworkRequestDispatcher &)> _sigQueueFinished
std::map< curl_socket_t, std::shared_ptr< SocketNotifier > > _socketHandler
static int static_socket_callback(CURL *easy, curl_socket_t s, int what, void *userp, SocketNotifier *socketp)
std::deque< std::shared_ptr< NetworkRequest > > _pendingDownloads
void handleMultiSocketAction(curl_socket_t nativeSocket, int evBitmask)
The NetworkRequestError class Represents a error that occured in.
Signal< void(NetworkRequestDispatcher &)> _sigError
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > _customHeaders
Signal< void(NetworkRequestDispatcher &, NetworkRequest &)> _sigDownloadStarted
void setFinished(NetworkRequest &req, NetworkRequestError result)
Signal< void(NetworkRequestDispatcher &, NetworkRequest &)> _sigDownloadFinished
std::vector< std::shared_ptr< NetworkRequest > > _runningDownloads
void onSocketActivated(const SocketNotifier &listener, int events)