From 1f710d29c1b51257327809b55823a7005c0ab7e0 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 7 Aug 2011 00:36:44 +0900 Subject: [PATCH] Rewritten SessionSerializer using BufferedFile --- src/SessionSerializer.cc | 88 ++++++++++++++++++++++++----------- src/SessionSerializer.h | 4 +- test/SessionSerializerTest.cc | 7 +-- 3 files changed, 67 insertions(+), 32 deletions(-) diff --git a/src/SessionSerializer.cc b/src/SessionSerializer.cc index e904a5ff..b3cfd572 100644 --- a/src/SessionSerializer.cc +++ b/src/SessionSerializer.cc @@ -34,7 +34,7 @@ /* copyright --> */ #include "SessionSerializer.h" -#include +#include #include #include "RequestGroupMan.h" @@ -48,6 +48,7 @@ #include "prefs.h" #include "util.h" #include "array_fun.h" +#include "BufferedFile.h" namespace aria2 { @@ -62,13 +63,11 @@ bool SessionSerializer::save(const std::string& filename) const { std::string tempFilename = strconcat(filename, "__temp"); { - std::ofstream out(tempFilename.c_str(), std::ios::binary); - if(!out) { + BufferedFile fp(tempFilename, BufferedFile::WRITE); + if(!fp) { return false; } - save(out); - out.flush(); - if(!out) { + if(!save(fp) || fp.close() == EOF) { return false; } } @@ -101,7 +100,7 @@ bool inCumulativeOpts(const std::string& opt) } // namespace namespace { -void writeOption(std::ostream& out, const SharedHandle