11#include <zypp-core/zyppng/base/EventDispatcher>
12#include <zypp-core/zyppng/base/Signals>
34 successfulTransfers++;
55 return ( runningTransfers < maxConnections() );
60 const auto newCount = runningTransfers - 1;
67 _parent._sigNewMirrorsReady.emit();
80 _dispatcher = std::make_shared<NetworkRequestDispatcher>();
81 _queueEmptyConn =
_dispatcher->connectFunc( &NetworkRequestDispatcher::sigQueueFinished, [
this ]( NetworkRequestDispatcher& ) {
84 std::vector< std::unordered_map<std::string, MirrorHandle>::const_iterator >
allOfEm;
89 std::sort(
allOfEm.begin(),
allOfEm.end(), [](
const auto &
a,
const auto &
b ){
90 return ( zypp::str::compareCI( a->second->mirrorUrl.asString().c_str(), b->second->mirrorUrl.asString().c_str() ) < 0 );
93 DBG_MEDIA <<
"Finished probing mirrors, these are the results: \n";
95 DBG_MEDIA <<
"Mirror: " <<
iter->second->mirrorUrl <<
", rating is: " <<
iter->second->rating <<
"\n";
97 DBG_MEDIA <<
"End Mirror probing results." << std::endl;
115 MIL <<
"Destroying MirrorControl while measurements are still running, aborting" << std::endl;
117 if (
mirr.second->_request ) {
118 mirr.second->_finishedConn.disconnect();
129 for (
const auto &
mirror : urls ) {
131 const auto scheme =
mirror.url.getScheme();
132 if ( scheme ==
"http" || scheme ==
"https" || scheme ==
"ftp" || scheme ==
"tftp" ) {
158 const auto timings = req.
timings();
161 connTime = std::chrono::duration_cast<std::chrono::milliseconds>(timings->connect - timings->namelookup);
203 if (
hdlIt->second->_request ) {
216 return a.second->rating < b.second->rating;
221 if ( !
mirr.second->hasFreeConnections() ) {
225 if (
mirr.second->failedTransfers >= 10 )
261 _data = std::make_shared<Helper>( handle,
false );
264 MirrorRef::~MirrorRef()
267 void MirrorRef::startTransfer()
269 _data->_myHandle->startTransfer();
270 _data->_cancelOnDestruct =
true;
273 void MirrorRef::finishTransfer(
const bool success)
275 _data->_cancelOnDestruct =
false;
276 _data->_myHandle->finishTransfer( success );
279 void MirrorRef::cancelTransfer()
281 _data->_cancelOnDestruct =
false;
282 _data->_myHandle->cancelTransfer();
285 MirrorRef::operator
bool()
const
287 return _data->_myHandle.operator
bool();
292 return _data->_myHandle;
295 MirrorRef::Helper::~Helper()
297 if ( _cancelOnDestruct )
298 _myHandle->cancelTransfer();
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
std::string asString() const
Returns a default string representation of the Url object.
PickResult pickBestMirror(const std::vector< Url > &mirrors)
sigc::connection _queueEmptyConn
Timer::Ptr _newMirrSigDelay
std::shared_ptr< Mirror > MirrorHandle
void registerMirrors(const std::vector< zypp::media::MetalinkMirror > &urls)
std::string makeKey(const zypp::Url &url) const
std::shared_ptr< MirrorControl > Ptr
SignalProxy< void()> sigAllMirrorsReady()
SignalProxy< void()> sigNewMirrorsReady()
Signal< void()> _sigNewMirrorsReady
NetworkRequestDispatcher::Ptr _dispatcher
std::unordered_map< std::string, MirrorHandle > _handles
Signal< void()> _sigAllMirrorsReady
~MirrorControl() override
The NetworkRequestError class Represents a error that occured in.
std::string toString() const
toString Returns a string representation of the error
bool hasError() const
Checks if there was a error with the request.
std::optional< Timings > timings() const
After the request is finished query the timings that were collected during download.
std::string extendedErrorString() const
In some cases, curl can provide extended error information collected at runtime.
NetworkRequestError error() const
Returns the last set Error.
SignalProxy< void(NetworkRequest &req, const NetworkRequestError &err) sigFinished)()
Signals that the download finished.
static std::shared_ptr< Timer > create()
Creates a new Timer object, the timer is not started at this point.
SignalProxy< void(Timer &t) sigExpired)()
This signal is always emitted when the timer expires.
constexpr uint defaultMaxConnections
constexpr uint defaultSampleTime
constexpr uint penaltyIncrease
static const ViewOption WITH_SCHEME
Option to include scheme name in the URL string.
static const ViewOption WITH_PORT
Option to include port number in the URL string.
static const ViewOption EMPTY_AUTHORITY
Explicitely include the URL authority separator "//".
static const ViewOption WITH_HOST
Option to include hostname in the URL string.
void finishTransfer(const bool success)
uint maxConnections() const
bool hasFreeConnections() const
Mirror(MirrorControl &parent)