Use std::string for SocketPoolEntry::options_

Currently, we only store 1 value for FTP download. std::map is
overkill in the this situation.
pull/28/head
Tatsuhiro Tsujikawa 2012-09-26 23:00:05 +09:00
parent c13dc166de
commit a20e279606
5 changed files with 33 additions and 31 deletions

View File

@ -328,7 +328,7 @@ void DownloadEngine::poolSocket
const std::string& proxyhost,
uint16_t proxyport,
const SharedHandle<SocketCore>& sock,
const std::map<std::string, std::string>& options,
const std::string& options,
time_t timeout)
{
SocketPoolEntry e(sock, options, timeout);
@ -387,7 +387,7 @@ void DownloadEngine::poolSocket
const std::string& username,
const SharedHandle<Request>& proxyRequest,
const SharedHandle<SocketCore>& socket,
const std::map<std::string, std::string>& options,
const std::string& options,
time_t timeout)
{
if(!proxyRequest) {
@ -441,7 +441,7 @@ DownloadEngine::popPooledSocket
SharedHandle<SocketCore>
DownloadEngine::popPooledSocket
(std::map<std::string, std::string>& options,
(std::string& options,
const std::string& ipaddr, uint16_t port,
const std::string& username,
const std::string& proxyhost, uint16_t proxyport)
@ -475,7 +475,7 @@ DownloadEngine::popPooledSocket
SharedHandle<SocketCore>
DownloadEngine::popPooledSocket
(std::map<std::string, std::string>& options,
(std::string& options,
const std::vector<std::string>& ipaddrs, uint16_t port,
const std::string& username)
{
@ -492,16 +492,18 @@ DownloadEngine::popPooledSocket
DownloadEngine::SocketPoolEntry::SocketPoolEntry
(const SharedHandle<SocketCore>& socket,
const std::map<std::string, std::string>& options,
time_t timeout):
socket_(socket),
options_(options),
timeout_(timeout) {}
const std::string& options,
time_t timeout)
: socket_(socket),
options_(options),
timeout_(timeout)
{}
DownloadEngine::SocketPoolEntry::SocketPoolEntry
(const SharedHandle<SocketCore>& socket, time_t timeout):
socket_(socket),
timeout_(timeout) {}
(const SharedHandle<SocketCore>& socket, time_t timeout)
: socket_(socket),
timeout_(timeout)
{}
DownloadEngine::SocketPoolEntry::~SocketPoolEntry() {}

View File

@ -84,15 +84,15 @@ private:
class SocketPoolEntry {
private:
SharedHandle<SocketCore> socket_;
std::map<std::string, std::string> options_;
// protocol specific option string
std::string options_;
time_t timeout_;
Timer registeredTime_;
public:
SocketPoolEntry(const SharedHandle<SocketCore>& socket,
const std::map<std::string, std::string>& option,
const std::string& option,
time_t timeout);
SocketPoolEntry(const SharedHandle<SocketCore>& socket,
@ -107,7 +107,7 @@ private:
return socket_;
}
const std::map<std::string, std::string>& getOptions() const
const std::string& getOptions() const
{
return options_;
}
@ -242,14 +242,14 @@ public:
const std::string& username,
const std::string& proxyhost, uint16_t proxyport,
const SharedHandle<SocketCore>& sock,
const std::map<std::string, std::string>& options,
const std::string& options,
time_t timeout = 15);
void poolSocket(const SharedHandle<Request>& request,
const std::string& username,
const SharedHandle<Request>& proxyRequest,
const SharedHandle<SocketCore>& socket,
const std::map<std::string, std::string>& options,
const std::string& options,
time_t timeout = 15);
void poolSocket(const std::string& ipaddr, uint16_t port,
@ -268,7 +268,7 @@ public:
const std::string& proxyhost, uint16_t proxyport);
SharedHandle<SocketCore> popPooledSocket
(std::map<std::string, std::string>& options,
(std::string& options,
const std::string& ipaddr,
uint16_t port,
const std::string& username,
@ -280,7 +280,7 @@ public:
SharedHandle<SocketCore>
popPooledSocket
(std::map<std::string, std::string>& options,
(std::string& options,
const std::vector<std::string>& ipaddrs,
uint16_t port,
const std::string& username);

View File

@ -85,11 +85,9 @@ bool FtpFinishDownloadCommand::execute()
}
if(status == 226) {
if(getOption()->getAsBool(PREF_FTP_REUSE_CONNECTION)) {
std::map<std::string, std::string> options;
options["baseWorkingDir"] = ftpConnection_->getBaseWorkingDir();
getDownloadEngine()->poolSocket
(getRequest(), ftpConnection_->getUser(), createProxyRequest(),
getSocket(), options);
getSocket(), ftpConnection_->getBaseWorkingDir());
}
} else {
A2_LOG_INFO(fmt("CUID#%" PRId64 " - Bad status for transfer complete.",

View File

@ -76,7 +76,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand
{
Command* command;
if(proxyRequest) {
std::map<std::string, std::string> options;
std::string options;
SharedHandle<SocketCore> pooledSocket;
std::string proxyMethod = resolveProxyMethod(getRequest()->getProtocol());
if(proxyMethod == V_GET) {
@ -124,12 +124,13 @@ Command* FtpInitiateConnectionCommand::createNextCommand
} else {
setConnectedAddrInfo(getRequest(), hostname, pooledSocket);
if(proxyMethod == V_TUNNEL) {
// options contains "baseWorkingDir"
command =
new FtpNegotiationCommand(getCuid(), getRequest(), getFileEntry(),
getRequestGroup(), getDownloadEngine(),
pooledSocket,
FtpNegotiationCommand::SEQ_SEND_CWD_PREP,
options["baseWorkingDir"]);
options);
} else if(proxyMethod == V_GET) {
// Use GET for FTP via HTTP proxy.
getRequest()->setMethod(Request::METHOD_GET);
@ -150,7 +151,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand
}
}
} else {
std::map<std::string, std::string> options;
std::string options;
SharedHandle<SocketCore> pooledSocket =
getDownloadEngine()->popPooledSocket
(options, resolvedAddresses,
@ -169,12 +170,13 @@ Command* FtpInitiateConnectionCommand::createNextCommand
getRequest()->setConnectedAddrInfo(hostname, addr, port);
command = c;
} else {
// options contains "baseWorkingDir"
command =
new FtpNegotiationCommand(getCuid(), getRequest(), getFileEntry(),
getRequestGroup(), getDownloadEngine(),
pooledSocket,
FtpNegotiationCommand::SEQ_SEND_CWD_PREP,
options["baseWorkingDir"]);
options);
setConnectedAddrInfo(getRequest(), hostname, pooledSocket);
}
}

View File

@ -959,10 +959,10 @@ bool FtpNegotiationCommand::processSequence
void FtpNegotiationCommand::poolConnection() const
{
if(getOption()->getAsBool(PREF_FTP_REUSE_CONNECTION)) {
std::map<std::string, std::string> options;
options["baseWorkingDir"] = ftp_->getBaseWorkingDir();
// Store ftp_->getBaseWorkingDir() as options
getDownloadEngine()->poolSocket(getRequest(), ftp_->getUser(),
createProxyRequest(), getSocket(), options);
createProxyRequest(), getSocket(),
ftp_->getBaseWorkingDir());
}
}