mirror of https://github.com/aria2/aria2
Cleanup AbstractCommand take 2
Decided to keep the 'if(' -> 'if (' stuff, as I formatted the whole file and so it is internally consistent within the file. Also, too much hassle.pull/235/head
parent
e57d330111
commit
8cada49765
File diff suppressed because it is too large
Load Diff
|
@ -62,7 +62,8 @@ class AsyncNameResolver;
|
||||||
class AsyncNameResolverMan;
|
class AsyncNameResolverMan;
|
||||||
#endif // ENABLE_ASYNC_DNS
|
#endif // ENABLE_ASYNC_DNS
|
||||||
|
|
||||||
class AbstractCommand : public Command {
|
class AbstractCommand : public Command
|
||||||
|
{
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<Request> req_;
|
std::shared_ptr<Request> req_;
|
||||||
std::shared_ptr<FileEntry> fileEntry_;
|
std::shared_ptr<FileEntry> fileEntry_;
|
||||||
|
@ -78,7 +79,7 @@ private:
|
||||||
RequestGroup* requestGroup_;
|
RequestGroup* requestGroup_;
|
||||||
DownloadEngine* e_;
|
DownloadEngine* e_;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Segment> > segments_;
|
std::vector<std::shared_ptr<Segment>> segments_;
|
||||||
|
|
||||||
Timer checkPoint_;
|
Timer checkPoint_;
|
||||||
Timer serverStatTimer_;
|
Timer serverStatTimer_;
|
||||||
|
@ -90,8 +91,11 @@ private:
|
||||||
bool incNumConnection_;
|
bool incNumConnection_;
|
||||||
|
|
||||||
int32_t calculateMinSplitSize() const;
|
int32_t calculateMinSplitSize() const;
|
||||||
|
|
||||||
void useFasterRequest(const std::shared_ptr<Request>& fasterRequest);
|
void useFasterRequest(const std::shared_ptr<Request>& fasterRequest);
|
||||||
|
|
||||||
|
bool shouldProcess() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RequestGroup* getRequestGroup() const
|
RequestGroup* getRequestGroup() const
|
||||||
{
|
{
|
||||||
|
@ -140,7 +144,7 @@ public:
|
||||||
return socketRecvBuffer_;
|
return socketRecvBuffer_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<std::shared_ptr<Segment> >& getSegments() const
|
const std::vector<std::shared_ptr<Segment>>& getSegments() const
|
||||||
{
|
{
|
||||||
return segments_;
|
return segments_;
|
||||||
}
|
}
|
||||||
|
@ -150,26 +154,32 @@ public:
|
||||||
// return empty string. In this case, call this function with same
|
// return empty string. In this case, call this function with same
|
||||||
// arguments until resolved address is returned. Exception is
|
// arguments until resolved address is returned. Exception is
|
||||||
// thrown on error. port is used for retrieving cached addresses.
|
// thrown on error. port is used for retrieving cached addresses.
|
||||||
std::string resolveHostname
|
std::string resolveHostname(std::vector<std::string>& addrs,
|
||||||
(std::vector<std::string>& addrs, const std::string& hostname, uint16_t port);
|
const std::string& hostname,
|
||||||
|
uint16_t port);
|
||||||
|
|
||||||
void tryReserved();
|
void tryReserved();
|
||||||
|
|
||||||
void setReadCheckSocket(const std::shared_ptr<SocketCore>& socket);
|
void setReadCheckSocket(const std::shared_ptr<SocketCore>& socket);
|
||||||
|
|
||||||
void setWriteCheckSocket(const std::shared_ptr<SocketCore>& socket);
|
void setWriteCheckSocket(const std::shared_ptr<SocketCore>& socket);
|
||||||
|
|
||||||
void disableReadCheckSocket();
|
void disableReadCheckSocket();
|
||||||
|
|
||||||
void disableWriteCheckSocket();
|
void disableWriteCheckSocket();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If pred == true, calls setReadCheckSocket(socket). Otherwise, calls
|
* If pred == true, calls setReadCheckSocket(socket). Otherwise, calls
|
||||||
* disableReadCheckSocket().
|
* disableReadCheckSocket().
|
||||||
*/
|
*/
|
||||||
void setReadCheckSocketIf(const std::shared_ptr<SocketCore>& socket, bool pred);
|
void setReadCheckSocketIf(const std::shared_ptr<SocketCore>& socket,
|
||||||
|
bool pred);
|
||||||
/**
|
/**
|
||||||
* If pred == true, calls setWriteCheckSocket(socket). Otherwise, calls
|
* If pred == true, calls setWriteCheckSocket(socket). Otherwise, calls
|
||||||
* disableWriteCheckSocket().
|
* disableWriteCheckSocket().
|
||||||
*/
|
*/
|
||||||
void setWriteCheckSocketIf(const std::shared_ptr<SocketCore>& socket, bool pred);
|
void setWriteCheckSocketIf(const std::shared_ptr<SocketCore>& socket,
|
||||||
|
bool pred);
|
||||||
|
|
||||||
// Swaps socket_ with socket. This disables current read and write
|
// Swaps socket_ with socket. This disables current read and write
|
||||||
// check.
|
// check.
|
||||||
|
@ -180,7 +190,10 @@ public:
|
||||||
return timeout_;
|
return timeout_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTimeout(time_t timeout) { timeout_ = timeout; }
|
void setTimeout(time_t timeout)
|
||||||
|
{
|
||||||
|
timeout_ = timeout;
|
||||||
|
}
|
||||||
|
|
||||||
void prepareForNextAction(std::unique_ptr<CheckIntegrityEntry> checkEntry);
|
void prepareForNextAction(std::unique_ptr<CheckIntegrityEntry> checkEntry);
|
||||||
|
|
||||||
|
@ -189,8 +202,7 @@ public:
|
||||||
// InitiateConnectionCommandFactory and it is pushed to
|
// InitiateConnectionCommandFactory and it is pushed to
|
||||||
// DownloadEngine and returns false. If no addresses left, DlRetryEx
|
// DownloadEngine and returns false. If no addresses left, DlRetryEx
|
||||||
// exception is thrown.
|
// exception is thrown.
|
||||||
bool checkIfConnectionEstablished
|
bool checkIfConnectionEstablished(const std::shared_ptr<SocketCore>& socket,
|
||||||
(const std::shared_ptr<SocketCore>& socket,
|
|
||||||
const std::string& connectedHostname,
|
const std::string& connectedHostname,
|
||||||
const std::string& connectedAddr,
|
const std::string& connectedAddr,
|
||||||
uint16_t connectedPort);
|
uint16_t connectedPort);
|
||||||
|
@ -225,33 +237,40 @@ public:
|
||||||
void checkSocketRecvBuffer();
|
void checkSocketRecvBuffer();
|
||||||
|
|
||||||
void addCommandSelf();
|
void addCommandSelf();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool prepareForRetry(time_t wait);
|
virtual bool prepareForRetry(time_t wait);
|
||||||
|
|
||||||
virtual void onAbort();
|
virtual void onAbort();
|
||||||
|
|
||||||
virtual bool executeInternal() = 0;
|
virtual bool executeInternal() = 0;
|
||||||
|
|
||||||
// Returns true if the derived class wants to execute
|
// Returns true if the derived class wants to execute
|
||||||
// executeInternal() unconditionally
|
// executeInternal() unconditionally
|
||||||
virtual bool noCheck()
|
virtual bool noCheck() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AbstractCommand(cuid_t cuid, const std::shared_ptr<Request>& req,
|
AbstractCommand(cuid_t cuid,
|
||||||
|
const std::shared_ptr<Request>& req,
|
||||||
const std::shared_ptr<FileEntry>& fileEntry,
|
const std::shared_ptr<FileEntry>& fileEntry,
|
||||||
RequestGroup* requestGroup, DownloadEngine* e,
|
RequestGroup* requestGroup,
|
||||||
|
DownloadEngine* e,
|
||||||
const std::shared_ptr<SocketCore>& s = nullptr,
|
const std::shared_ptr<SocketCore>& s = nullptr,
|
||||||
const std::shared_ptr<SocketRecvBuffer>& socketRecvBuffer = nullptr,
|
const std::shared_ptr<SocketRecvBuffer>& socketRecvBuffer =
|
||||||
|
nullptr,
|
||||||
bool incNumConnection = true);
|
bool incNumConnection = true);
|
||||||
|
|
||||||
virtual ~AbstractCommand();
|
virtual ~AbstractCommand();
|
||||||
|
|
||||||
virtual bool execute() CXX11_OVERRIDE;
|
virtual bool execute() CXX11_OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns proxy URI for given protocol. If no proxy URI is defined,
|
// Returns proxy URI for given protocol. If no proxy URI is defined,
|
||||||
// then returns an empty string.
|
// then returns an empty string.
|
||||||
std::string getProxyUri
|
std::string getProxyUri(const std::string& protocol, const Option* option);
|
||||||
(const std::string& protocol, const Option* option);
|
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,7 @@ bool ConnectCommand::executeInternal()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConnectCommand::noCheck()
|
bool ConnectCommand::noCheck() const
|
||||||
{
|
{
|
||||||
return backupConnectionInfo_ && !backupConnectionInfo_->ipaddr.empty();
|
return backupConnectionInfo_ && !backupConnectionInfo_->ipaddr.empty();
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ public:
|
||||||
const std::shared_ptr<Request>& getProxyRequest() const;
|
const std::shared_ptr<Request>& getProxyRequest() const;
|
||||||
protected:
|
protected:
|
||||||
virtual bool executeInternal() CXX11_OVERRIDE;
|
virtual bool executeInternal() CXX11_OVERRIDE;
|
||||||
virtual bool noCheck() CXX11_OVERRIDE;
|
virtual bool noCheck() const CXX11_OVERRIDE;
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<Request> proxyRequest_;
|
std::shared_ptr<Request> proxyRequest_;
|
||||||
std::shared_ptr<BackupConnectInfo> backupConnectionInfo_;
|
std::shared_ptr<BackupConnectInfo> backupConnectionInfo_;
|
||||||
|
|
|
@ -241,6 +241,11 @@ public:
|
||||||
|
|
||||||
int64_t getCompletedLength() const;
|
int64_t getCompletedLength() const;
|
||||||
|
|
||||||
|
inline int64_t getPendingLength() const
|
||||||
|
{
|
||||||
|
return getTotalLength() - getCompletedLength();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares expected filename with specified actualFilename.
|
* Compares expected filename with specified actualFilename.
|
||||||
* The expected filename refers to FileEntry::getBasename() of the first
|
* The expected filename refers to FileEntry::getBasename() of the first
|
||||||
|
|
Loading…
Reference in New Issue