Update AIHTTPTimeoutPolicy objects when their base changes.
Actually propagate changes to CurlTimeout* Debug Settings to the timeout policy objects.
This commit is contained in:
@@ -105,6 +105,7 @@ AIHTTPTimeoutPolicy& AIHTTPTimeoutPolicy::operator=(AIHTTPTimeoutPolicy const& r
|
|||||||
mLowSpeedLimit = rhs.mLowSpeedLimit;
|
mLowSpeedLimit = rhs.mLowSpeedLimit;
|
||||||
mMaximumCurlTransaction = rhs.mMaximumCurlTransaction;
|
mMaximumCurlTransaction = rhs.mMaximumCurlTransaction;
|
||||||
mMaximumTotalDelay = rhs.mMaximumTotalDelay;
|
mMaximumTotalDelay = rhs.mMaximumTotalDelay;
|
||||||
|
changed();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,19 +137,27 @@ struct PolicyOp {
|
|||||||
class AIHTTPTimeoutPolicyBase : public AIHTTPTimeoutPolicy {
|
class AIHTTPTimeoutPolicyBase : public AIHTTPTimeoutPolicy {
|
||||||
private:
|
private:
|
||||||
std::vector<AIHTTPTimeoutPolicy*> mDerived; // Policies derived from this one.
|
std::vector<AIHTTPTimeoutPolicy*> mDerived; // Policies derived from this one.
|
||||||
|
PolicyOp const* mOp; // Operator we applied to base to get ourselves.
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AIHTTPTimeoutPolicyBase(U16 dns_lookup_grace, U16 subsequent_connects, U16 reply_delay,
|
AIHTTPTimeoutPolicyBase(U16 dns_lookup_grace, U16 subsequent_connects, U16 reply_delay,
|
||||||
U16 low_speed_time, U32 low_speed_limit,
|
U16 low_speed_time, U32 low_speed_limit,
|
||||||
U16 curl_transaction, U16 total_delay) :
|
U16 curl_transaction, U16 total_delay) :
|
||||||
AIHTTPTimeoutPolicy(NULL, dns_lookup_grace, subsequent_connects, reply_delay, low_speed_time, low_speed_limit, curl_transaction, total_delay) { }
|
AIHTTPTimeoutPolicy(NULL, dns_lookup_grace, subsequent_connects, reply_delay, low_speed_time, low_speed_limit, curl_transaction, total_delay),
|
||||||
|
mOp(NULL) { }
|
||||||
|
|
||||||
// Derive base from base.
|
// Derive base from base.
|
||||||
AIHTTPTimeoutPolicyBase(AIHTTPTimeoutPolicyBase& rhs, PolicyOp const& op) : AIHTTPTimeoutPolicy(rhs) { op.perform(this); }
|
AIHTTPTimeoutPolicyBase(AIHTTPTimeoutPolicyBase& rhs, PolicyOp& op) : AIHTTPTimeoutPolicy(rhs), mOp(&op) { rhs.derived(this); mOp->perform(this); }
|
||||||
|
|
||||||
// Called for every derived policy.
|
// Called for every derived policy.
|
||||||
void derived(AIHTTPTimeoutPolicy* derived) { mDerived.push_back(derived); }
|
void derived(AIHTTPTimeoutPolicy* derived) { mDerived.push_back(derived); }
|
||||||
|
|
||||||
|
// Called when our base changed.
|
||||||
|
/*virtual*/ void base_changed(void);
|
||||||
|
|
||||||
|
// Called when we ourselves changed.
|
||||||
|
/*virtual*/ void changed(void);
|
||||||
|
|
||||||
// Provide public acces to sDebugSettingsCurlTimeout for this compilation unit.
|
// Provide public acces to sDebugSettingsCurlTimeout for this compilation unit.
|
||||||
static AIHTTPTimeoutPolicyBase& getDebugSettingsCurlTimeout(void) { return sDebugSettingsCurlTimeout; }
|
static AIHTTPTimeoutPolicyBase& getDebugSettingsCurlTimeout(void) { return sDebugSettingsCurlTimeout; }
|
||||||
|
|
||||||
@@ -157,6 +166,27 @@ class AIHTTPTimeoutPolicyBase : public AIHTTPTimeoutPolicy {
|
|||||||
AIHTTPTimeoutPolicyBase& operator=(AIHTTPTimeoutPolicy const& rhs);
|
AIHTTPTimeoutPolicyBase& operator=(AIHTTPTimeoutPolicy const& rhs);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void AIHTTPTimeoutPolicyBase::base_changed(void)
|
||||||
|
{
|
||||||
|
AIHTTPTimeoutPolicy::base_changed();
|
||||||
|
if (mOp)
|
||||||
|
mOp->perform(this);
|
||||||
|
changed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AIHTTPTimeoutPolicyBase::changed(void)
|
||||||
|
{
|
||||||
|
for (std::vector<AIHTTPTimeoutPolicy*>::iterator iter = mDerived.begin(); iter != mDerived.end(); ++iter)
|
||||||
|
(*iter)->base_changed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AIHTTPTimeoutPolicy::changed(void)
|
||||||
|
{
|
||||||
|
Dout(dc::notice, "Policy \"" << mName << "\" changed into: DNSLookup: " << mDNSLookupGrace << "; Connect: " << mMaximumConnectTime <<
|
||||||
|
"; ReplyDelay: " << mMaximumReplyDelay << "; LowSpeedTime: " << mLowSpeedTime << "; LowSpeedLimit: " << mLowSpeedLimit <<
|
||||||
|
"; MaxTransaction: " << mMaximumCurlTransaction << "; MaxTotalDelay:" << mMaximumTotalDelay);
|
||||||
|
}
|
||||||
|
|
||||||
AIHTTPTimeoutPolicy::AIHTTPTimeoutPolicy(AIHTTPTimeoutPolicy& base) :
|
AIHTTPTimeoutPolicy::AIHTTPTimeoutPolicy(AIHTTPTimeoutPolicy& base) :
|
||||||
mName(NULL),
|
mName(NULL),
|
||||||
mBase(static_cast<AIHTTPTimeoutPolicyBase*>(&base)),
|
mBase(static_cast<AIHTTPTimeoutPolicyBase*>(&base)),
|
||||||
@@ -192,6 +222,19 @@ AIHTTPTimeoutPolicy::AIHTTPTimeoutPolicy(char const* name, AIHTTPTimeoutPolicyBa
|
|||||||
mBase->derived(this);
|
mBase->derived(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AIHTTPTimeoutPolicy::base_changed(void)
|
||||||
|
{
|
||||||
|
// The same as *this = *mBase; but can't use operator= because of an assert that checks that mBase is not set.
|
||||||
|
mDNSLookupGrace = mBase->mDNSLookupGrace;
|
||||||
|
mMaximumConnectTime = mBase->mMaximumConnectTime;
|
||||||
|
mMaximumReplyDelay = mBase->mMaximumReplyDelay;
|
||||||
|
mLowSpeedTime = mBase->mLowSpeedTime;
|
||||||
|
mLowSpeedLimit = mBase->mLowSpeedLimit;
|
||||||
|
mMaximumCurlTransaction = mBase->mMaximumCurlTransaction;
|
||||||
|
mMaximumTotalDelay = mBase->mMaximumTotalDelay;
|
||||||
|
changed();
|
||||||
|
}
|
||||||
|
|
||||||
//static
|
//static
|
||||||
void AIHTTPTimeoutPolicy::setDefaultCurlTimeout(AIHTTPTimeoutPolicy const& timeout)
|
void AIHTTPTimeoutPolicy::setDefaultCurlTimeout(AIHTTPTimeoutPolicy const& timeout)
|
||||||
{
|
{
|
||||||
@@ -631,8 +674,8 @@ AIHTTPTimeoutPolicyBase AIHTTPTimeoutPolicy::sDebugSettingsCurlTimeout(
|
|||||||
AITP_default_maximum_curl_transaction,
|
AITP_default_maximum_curl_transaction,
|
||||||
AITP_default_maximum_total_delay);
|
AITP_default_maximum_total_delay);
|
||||||
|
|
||||||
// Note: Broken compiler doesn't allow as to use temporaries for the Operator ojects,
|
// Note: All operator objects (Transaction, Connect, etc) must be globals (not temporaries)!
|
||||||
// so they are instantiated separately.
|
// To enforce this they are passes as reference to non-const (but will never be changed).
|
||||||
|
|
||||||
// This used to be '5 seconds'.
|
// This used to be '5 seconds'.
|
||||||
Transaction transactionOp5s(5);
|
Transaction transactionOp5s(5);
|
||||||
|
|||||||
@@ -110,6 +110,12 @@ class AIHTTPTimeoutPolicy {
|
|||||||
// Called when a connect to a hostname timed out.
|
// Called when a connect to a hostname timed out.
|
||||||
static bool connect_timed_out(std::string const& hostname);
|
static bool connect_timed_out(std::string const& hostname);
|
||||||
|
|
||||||
|
// Called when the base that this policy was based on changed.
|
||||||
|
virtual void base_changed(void);
|
||||||
|
|
||||||
|
// Called when we ourselves changed.
|
||||||
|
virtual void changed(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Used by AIHTTPTimeoutPolicyBase::AIHTTPTimeoutPolicyBase(AIHTTPTimeoutPolicyBase&).
|
// Used by AIHTTPTimeoutPolicyBase::AIHTTPTimeoutPolicyBase(AIHTTPTimeoutPolicyBase&).
|
||||||
AIHTTPTimeoutPolicy(AIHTTPTimeoutPolicy&);
|
AIHTTPTimeoutPolicy(AIHTTPTimeoutPolicy&);
|
||||||
|
|||||||
Reference in New Issue
Block a user