|
@@ -46,10 +46,12 @@
|
|
|
|
|
|
namespace aria2 {
|
|
namespace aria2 {
|
|
|
|
|
|
-const std::string ServerStat::STATUS_STRING[] = {
|
|
|
|
|
|
+namespace {
|
|
|
|
+const char* STATUS_STRING[] = {
|
|
"OK",
|
|
"OK",
|
|
"ERROR"
|
|
"ERROR"
|
|
};
|
|
};
|
|
|
|
+} // namespace
|
|
|
|
|
|
ServerStat::ServerStat(const std::string& hostname, const std::string& protocol)
|
|
ServerStat::ServerStat(const std::string& hostname, const std::string& protocol)
|
|
: hostname_(hostname),
|
|
: hostname_(hostname),
|
|
@@ -161,18 +163,18 @@ void ServerStat::setStatus(STATUS status)
|
|
|
|
|
|
void ServerStat::setStatus(const std::string& status)
|
|
void ServerStat::setStatus(const std::string& status)
|
|
{
|
|
{
|
|
- const std::string* p = std::find(vbegin(STATUS_STRING), vend(STATUS_STRING),
|
|
|
|
- status);
|
|
|
|
- if(p != vend(STATUS_STRING)) {
|
|
|
|
- status_ = static_cast<STATUS>(ServerStat::OK+
|
|
|
|
- std::distance(vbegin(STATUS_STRING), p));
|
|
|
|
|
|
+ for(int i = 0; i < MAX_STATUS; ++i) {
|
|
|
|
+ if(strcmp(status.c_str(), STATUS_STRING[i]) == 0) {
|
|
|
|
+ status_ = static_cast<STATUS>(i);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void ServerStat::setStatusInternal(STATUS status)
|
|
void ServerStat::setStatusInternal(STATUS status)
|
|
{
|
|
{
|
|
A2_LOG_DEBUG(fmt("ServerStat: set status %s for %s (%s)",
|
|
A2_LOG_DEBUG(fmt("ServerStat: set status %s for %s (%s)",
|
|
- STATUS_STRING[status].c_str(),
|
|
|
|
|
|
+ STATUS_STRING[status],
|
|
hostname_.c_str(),
|
|
hostname_.c_str(),
|
|
protocol_.c_str()));
|
|
protocol_.c_str()));
|
|
status_ = status;
|
|
status_ = status;
|
|
@@ -211,7 +213,7 @@ std::string ServerStat::toString() const
|
|
getMultiConnectionAvgSpeed(),
|
|
getMultiConnectionAvgSpeed(),
|
|
getLastUpdated().getTime(),
|
|
getLastUpdated().getTime(),
|
|
getCounter(),
|
|
getCounter(),
|
|
- ServerStat::STATUS_STRING[getStatus()].c_str());
|
|
|
|
|
|
+ STATUS_STRING[getStatus()]);
|
|
}
|
|
}
|
|
|
|
|
|
} // namespace aria2
|
|
} // namespace aria2
|