Skip to content

Commit

Permalink
clang-format-5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuhiro-t committed Nov 23, 2017
1 parent 20a7c43 commit 795a047
Show file tree
Hide file tree
Showing 48 changed files with 597 additions and 286 deletions.
9 changes: 5 additions & 4 deletions examples/libaria2ex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ int main(int argc, char** argv)
if (dh) {
std::cerr << " [" << aria2::gidToHex(gid) << "] "
<< dh->getCompletedLength() << "/" << dh->getTotalLength()
<< "(" << (dh->getTotalLength() > 0
? (100 * dh->getCompletedLength() /
dh->getTotalLength())
: 0)
<< "("
<< (dh->getTotalLength() > 0
? (100 * dh->getCompletedLength() /
dh->getTotalLength())
: 0)
<< "%)"
<< " D:" << dh->getDownloadSpeed() / 1024
<< "KiB/s, U:" << dh->getUploadSpeed() / 1024 << "KiB/s"
Expand Down
49 changes: 27 additions & 22 deletions src/AbstractDiskWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void AbstractDiskWriter::openFile(int64_t totalLength)
#else // !__MINGW32__
e.getErrNum() == ENOENT
#endif // !__MINGW32__
) {
) {
initAndOpenFile(totalLength);
}
else {
Expand Down Expand Up @@ -201,9 +201,10 @@ HANDLE openFileWithFlags(const std::string& filename, int flags,
FILE_ATTRIBUTE_NORMAL, /* hTemplateFile */ 0);
if (hn == INVALID_HANDLE_VALUE) {
int errNum = GetLastError();
throw DL_ABORT_EX3(errNum, fmt(EX_FILE_OPEN, filename.c_str(),
fileStrerror(errNum).c_str()),
errCode);
throw DL_ABORT_EX3(
errNum,
fmt(EX_FILE_OPEN, filename.c_str(), fileStrerror(errNum).c_str()),
errCode);
}
return hn;
}
Expand All @@ -217,9 +218,10 @@ int openFileWithFlags(const std::string& filename, int flags,
;
if (fd < 0) {
int errNum = errno;
throw DL_ABORT_EX3(errNum, fmt(EX_FILE_OPEN, filename.c_str(),
util::safeStrerror(errNum).c_str()),
errCode);
throw DL_ABORT_EX3(
errNum,
fmt(EX_FILE_OPEN, filename.c_str(), util::safeStrerror(errNum).c_str()),
errCode);
}
util::make_fd_cloexec(fd);
#if defined(__APPLE__) && defined(__MACH__)
Expand Down Expand Up @@ -454,9 +456,10 @@ void AbstractDiskWriter::writeData(const unsigned char* data, size_t len,
error_code::NOT_ENOUGH_DISK_SPACE);
}
else {
throw DL_ABORT_EX3(errNum, fmt(EX_FILE_WRITE, filename_.c_str(),
fileStrerror(errNum).c_str()),
error_code::FILE_IO_ERROR);
throw DL_ABORT_EX3(
errNum,
fmt(EX_FILE_WRITE, filename_.c_str(), fileStrerror(errNum).c_str()),
error_code::FILE_IO_ERROR);
}
}
}
Expand All @@ -467,9 +470,10 @@ ssize_t AbstractDiskWriter::readData(unsigned char* data, size_t len,
ssize_t ret;
if ((ret = readDataInternal(data, len, offset)) < 0) {
int errNum = fileError();
throw DL_ABORT_EX3(errNum, fmt(EX_FILE_READ, filename_.c_str(),
fileStrerror(errNum).c_str()),
error_code::FILE_IO_ERROR);
throw DL_ABORT_EX3(
errNum,
fmt(EX_FILE_READ, filename_.c_str(), fileStrerror(errNum).c_str()),
error_code::FILE_IO_ERROR);
}
return ret;
}
Expand Down Expand Up @@ -526,17 +530,17 @@ void AbstractDiskWriter::allocate(int64_t offset, int64_t length, bool sparse)
}
#elif defined(__APPLE__) && defined(__MACH__)
const auto toalloc = offset + length - size();
fstore_t fstore = {
F_ALLOCATECONTIG | F_ALLOCATEALL, F_PEOFPOSMODE,
0, toalloc, 0};
fstore_t fstore = {F_ALLOCATECONTIG | F_ALLOCATEALL, F_PEOFPOSMODE, 0,
toalloc, 0};
if (fcntl(fd_, F_PREALLOCATE, &fstore) == -1) {
// Retry non-contig.
fstore.fst_flags = F_ALLOCATEALL;
if (fcntl(fd_, F_PREALLOCATE, &fstore) == -1) {
int err = errno;
throw DL_ABORT_EX3(
err, fmt("fcntl(F_PREALLOCATE) of %" PRId64 " failed. cause: %s",
fstore.fst_length, util::safeStrerror(err).c_str()),
err,
fmt("fcntl(F_PREALLOCATE) of %" PRId64 " failed. cause: %s",
fstore.fst_length, util::safeStrerror(err).c_str()),
error_code::FILE_IO_ERROR);
}
}
Expand All @@ -559,10 +563,11 @@ void AbstractDiskWriter::allocate(int64_t offset, int64_t length, bool sparse)
#elif HAVE_POSIX_FALLOCATE
int r = posix_fallocate(fd_, offset, length);
if (r != 0) {
throw DL_ABORT_EX3(r, fmt("posix_fallocate failed. cause: %s",
util::safeStrerror(r).c_str()),
isDiskFullError(r) ? error_code::NOT_ENOUGH_DISK_SPACE
: error_code::FILE_IO_ERROR);
throw DL_ABORT_EX3(
r,
fmt("posix_fallocate failed. cause: %s", util::safeStrerror(r).c_str()),
isDiskFullError(r) ? error_code::NOT_ENOUGH_DISK_SPACE
: error_code::FILE_IO_ERROR);
}
#else
#error "no *_fallocate function available."
Expand Down
6 changes: 3 additions & 3 deletions src/ActivePeerConnectionCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ bool ActivePeerConnectionCommand::execute()
int numConnection = 0;
if (pieceStorage_->downloadFinished()) {
if (btRuntime_->getMaxPeers() > btRuntime_->getConnections()) {
numConnection = std::min(numNewConnection_,
btRuntime_->getMaxPeers() -
btRuntime_->getConnections());
numConnection =
std::min(numNewConnection_, btRuntime_->getMaxPeers() -
btRuntime_->getConnections());
}
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src/AppleTLSSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@ class AppleTLSSession : public TLSSession {
OSStatus sockWrite(const void* data, size_t* len);
OSStatus sockRead(void* data, size_t* len);
};
}
} // namespace aria2

#endif // TLS_SESSION_H
2 changes: 1 addition & 1 deletion src/AsyncNameResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class AsyncNameResolver {
,
ares_addr_node* servers
#endif // HAVE_ARES_ADDR_NODE
);
);

~AsyncNameResolver();

Expand Down
2 changes: 1 addition & 1 deletion src/AsyncNameResolverMan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void AsyncNameResolverMan::startAsyncFamily(const std::string& hostname,
,
e->getAsyncDNSServers()
#endif // HAVE_ARES_ADDR_NODE
);
);
asyncNameResolver_[numResolver_]->resolve(hostname);
setNameResolverCheck(numResolver_, e, command);
}
Expand Down
5 changes: 3 additions & 2 deletions src/ChecksumCheckIntegrityEntry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ void ChecksumCheckIntegrityEntry::onDownloadIncomplete(
std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e)
{
if (redownload_) {
proceedFileAllocation(commands, make_unique<StreamFileAllocationEntry>(
getRequestGroup(), popNextCommand()),
proceedFileAllocation(commands,
make_unique<StreamFileAllocationEntry>(
getRequestGroup(), popNextCommand()),
e);
return;
}
Expand Down
5 changes: 2 additions & 3 deletions src/DHTBucket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,8 @@ bool DHTBucket::operator==(const DHTBucket& bucket) const

bool DHTBucket::needsRefresh() const
{
return nodes_.size() < K ||
lastUpdated_.difference(global::wallclock()) >=
DHT_BUCKET_REFRESH_INTERVAL;
return nodes_.size() < K || lastUpdated_.difference(global::wallclock()) >=
DHT_BUCKET_REFRESH_INTERVAL;
}

void DHTBucket::notifyUpdate() { lastUpdated_ = global::wallclock(); }
Expand Down
5 changes: 2 additions & 3 deletions src/DHTNode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ bool DHTNode::isBad() const { return condition_ >= BAD_CONDITION; }

bool DHTNode::isQuestionable() const
{
return !isBad() &&
lastContact_.difference(global::wallclock()) >=
DHT_NODE_CONTACT_INTERVAL;
return !isBad() && lastContact_.difference(global::wallclock()) >=
DHT_NODE_CONTACT_INTERVAL;
}

void DHTNode::markGood() { condition_ = 0; }
Expand Down
2 changes: 1 addition & 1 deletion src/DHTNodeLookupEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ struct DHTNodeLookupEntry {
bool operator==(const DHTNodeLookupEntry& entry) const;
};

} // namespace aria2;
} // namespace aria2

#endif // D_DHT_NODE_LOOKUP_ENTRY_H
6 changes: 3 additions & 3 deletions src/FtpConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ bool FtpConnection::sendPort(const std::shared_ptr<SocketCore>& serverSocket)
bool FtpConnection::sendRest(const std::shared_ptr<Segment>& segment)
{
if (socketBuffer_.sendBufferIsEmpty()) {
std::string request = fmt("REST %" PRId64 "\r\n",
segment ? segment->getPositionToWrite()
: static_cast<int64_t>(0LL));
std::string request =
fmt("REST %" PRId64 "\r\n", segment ? segment->getPositionToWrite()
: static_cast<int64_t>(0LL));
A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_, request.c_str()));
socketBuffer_.pushStr(std::move(request));
}
Expand Down
2 changes: 1 addition & 1 deletion src/HttpHeader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ bool HttpHeader::fieldContains(int hdKey, const char* value)
util::splitIter((*i).second.begin(), (*i).second.end(),
std::back_inserter(values), ',',
true // doStrip
);
);
for (const auto& v : values) {
if (util::strieq(v.first, v.second, value)) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/HttpHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,6 @@ class HttpHeader {

int idInterestingHeader(const char* hdName);

} // namespace
} // namespace aria2

#endif // D_HTTP_HEADER_H
10 changes: 4 additions & 6 deletions src/HttpResponseCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,8 @@ bool HttpResponseCommand::executeInternal()
// we ignore content-length when inflate is required
fe->setLength(0);
if (req->getMethod() == Request::METHOD_GET &&
(totalLength != 0 ||
!httpResponse->getHttpHeader()->defined(
HttpHeader::CONTENT_LENGTH))) {
(totalLength != 0 || !httpResponse->getHttpHeader()->defined(
HttpHeader::CONTENT_LENGTH))) {
// DownloadContext::knowsTotalLength() == true only when
// server says the size of file is 0 explicitly.
getDownloadContext()->markTotalLengthIsUnknown();
Expand Down Expand Up @@ -422,9 +421,8 @@ bool HttpResponseCommand::handleOtherEncoding(
httpResponse.get(), getContentEncodingStreamFilter(httpResponse.get()));
// If chunked transfer-encoding is specified, we have to read end of
// chunk markers(0\r\n\r\n, for example).
bool chunkedUsed =
streamFilter &&
streamFilter->getName() == ChunkedDecodingStreamFilter::NAME;
bool chunkedUsed = streamFilter && streamFilter->getName() ==
ChunkedDecodingStreamFilter::NAME;

// For zero-length file, check existing file comparing its size
if (!chunkedUsed && getDownloadContext()->knowsTotalLength() &&
Expand Down
4 changes: 2 additions & 2 deletions src/HttpServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ namespace util {
namespace security {
class HMAC;
class HMACResult;
}
}
} // namespace security
} // namespace util

enum RequestType { RPC_TYPE_NONE, RPC_TYPE_XML, RPC_TYPE_JSON, RPC_TYPE_JSONP };

Expand Down
4 changes: 2 additions & 2 deletions src/InitiateConnectionCommandFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ InitiateConnectionCommandFactory::createInitiateConnectionCommand(
// for SSL
|| req->getProtocol() == "https"
#endif // ENABLE_SSL
) {
) {

if (requestGroup->getOption()->getAsBool(PREF_ENABLE_HTTP_KEEP_ALIVE)) {
req->setKeepAliveHint(true);
Expand All @@ -74,7 +74,7 @@ InitiateConnectionCommandFactory::createInitiateConnectionCommand(
#ifdef HAVE_LIBSSH2
|| req->getProtocol() == "sftp"
#endif // HAVE_LIBSSH2
) {
) {
if (req->getFile().empty()) {
throw DL_ABORT_EX(fmt("FTP/SFTP URI %s doesn't contain file path.",
req->getUri().c_str()));
Expand Down
6 changes: 3 additions & 3 deletions src/LibgnutlsTLSSession.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ int GnuTLSSession::init(sock_t sockfd)

rv_ = gnutls_init(&sslSession_, flags);
#else // GNUTLS_VERSION_NUMBER >= 0x030000
rv_ = gnutls_init(&sslSession_,
tlsContext_->getSide() == TLS_CLIENT ? GNUTLS_CLIENT
: GNUTLS_SERVER);
rv_ = gnutls_init(&sslSession_, tlsContext_->getSide() == TLS_CLIENT
? GNUTLS_CLIENT
: GNUTLS_SERVER);
#endif // GNUTLS_VERSION_NUMBER >= 0x030000
if (rv_ != GNUTLS_E_SUCCESS) {
return TLS_ERR_ERROR;
Expand Down
9 changes: 4 additions & 5 deletions src/LibsslTLSContext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,14 @@ OpenSSLTLSContext::OpenSSLTLSContext(TLSSessionSide side, TLSVersion minVer)
};

// Disable SSLv2 and enable all workarounds for buggy servers
SSL_CTX_set_options(sslCtx_,
SSL_OP_ALL | SSL_OP_NO_SSLv2 | ver_opts
SSL_CTX_set_options(sslCtx_, SSL_OP_ALL | SSL_OP_NO_SSLv2 | ver_opts
#ifdef SSL_OP_SINGLE_ECDH_USE
| SSL_OP_SINGLE_ECDH_USE
| SSL_OP_SINGLE_ECDH_USE
#endif // SSL_OP_SINGLE_ECDH_USE
#ifdef SSL_OP_NO_COMPRESSION
| SSL_OP_NO_COMPRESSION
| SSL_OP_NO_COMPRESSION
#endif // SSL_OP_NO_COMPRESSION
);
);
SSL_CTX_set_mode(sslCtx_, SSL_MODE_AUTO_RETRY);
SSL_CTX_set_mode(sslCtx_, SSL_MODE_ENABLE_PARTIAL_WRITE);
#ifdef SSL_MODE_RELEASE_BUFFERS
Expand Down
2 changes: 1 addition & 1 deletion src/LibuvEventPoll.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ template <typename T> static void close_callback(uv_handle_t* handle)
}

static void timer_callback(uv_timer_t* handle) { uv_stop(handle->loop); }
}
} // namespace

namespace aria2 {

Expand Down
2 changes: 1 addition & 1 deletion src/LpdMessageDispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ std::string createLpdRequest(const std::string& multicastAddress,

} // namespace bittorrent

} // namespac aria2
} // namespace aria2
2 changes: 1 addition & 1 deletion src/MessageDigest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ HashTypeEntry hashTypes[] = {
HashTypeEntry("sha-512", 5), HashTypeEntry("md5", 0),
HashTypeEntry("adler32", 0),
};
} // namespace aria2
} // namespace

MessageDigest::MessageDigest(std::unique_ptr<MessageDigestImpl> impl)
: pImpl_{std::move(impl)}
Expand Down
7 changes: 4 additions & 3 deletions src/Metalink2RequestGroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ void Metalink2RequestGroup::generate(
const std::shared_ptr<Option>& option, const std::string& baseUri)
{
std::vector<std::shared_ptr<RequestGroup>> tempgroups;
createRequestGroup(tempgroups, metalink::parseAndQuery(binaryStream.get(),
option.get(), baseUri),
option);
createRequestGroup(
tempgroups,
metalink::parseAndQuery(binaryStream.get(), option.get(), baseUri),
option);
auto mi = std::make_shared<MetadataInfo>();
setMetadataInfo(std::begin(tempgroups), std::end(tempgroups), mi);
groups.insert(std::end(groups), std::begin(tempgroups), std::end(tempgroups));
Expand Down
2 changes: 1 addition & 1 deletion src/MetalinkParserController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ void MetalinkParserController::commitResourceTransaction()
else {
tEntry_->resources.push_back(std::move(tResource_));
}
#else // !ENABLE_BITTORRENT
#else // !ENABLE_BITTORRENT
tEntry_->resources.push_back(std::move(tResource_));
#endif // !ENABLE_BITTORRENT
tResource_.reset();
Expand Down
2 changes: 1 addition & 1 deletion src/NullWebSocketSessionMan.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ class WebSocketSessionMan {

} // namespace rpc

} // aria2
} // namespace aria2

#endif // D_NULL_WEB_SOCKET_SESSION_MAN_H
5 changes: 2 additions & 3 deletions src/OpenedFileCounter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ void OpenedFileCounter::ensureMaxOpenFileLimit(size_t numNewFiles)
auto& requestGroups = rgman_->getRequestGroups();

auto mark = std::begin(requestGroups);
std::advance(
mark,
SimpleRandomizer::getInstance()->getRandomNumber(requestGroups.size()));
std::advance(mark, SimpleRandomizer::getInstance()->getRandomNumber(
requestGroups.size()));

auto closeFun = [&left](const std::shared_ptr<RequestGroup>& group) {
auto& ps = group->getPieceStorage();
Expand Down
Loading

0 comments on commit 795a047

Please sign in to comment.