From c7152c8f97d01dda4eeb70869a0d28cc9a04df1f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sat, 28 Mar 2009 19:41:53 +0000 Subject: [PATCH] * Don't use the non-standard __gnu_cxx::stdio_filebuf class. --- src/libstore/local-store.cc | 41 +++++++++++++++---------------------- src/libstore/local-store.hh | 9 +------- 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index d4eda78a7..9f9c378c6 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -88,8 +88,8 @@ LocalStore::~LocalStore() flushDelayedUpdates(); foreach (RunningSubstituters::iterator, i, runningSubstituters) { - i->second.toBuf.reset(); - i->second.to.reset(); + i->second.to.close(); + i->second.from.close(); i->second.pid.wait(true); } @@ -526,23 +526,16 @@ void LocalStore::startSubstituter(const Path & substituter, RunningSubstituter & /* Parent. */ - toPipe.readSide.close(); - fromPipe.writeSide.close(); - - run.toBuf = boost::shared_ptr(new stdio_filebuf(toPipe.writeSide.borrow(), std::ios_base::out)); - run.to = boost::shared_ptr(new std::ostream(&*run.toBuf)); - - run.fromBuf = boost::shared_ptr(new stdio_filebuf(fromPipe.readSide.borrow(), std::ios_base::in)); - run.from = boost::shared_ptr(new std::istream(&*run.fromBuf)); + run.to = toPipe.writeSide.borrow(); + run.from = fromPipe.readSide.borrow(); } -template T getIntLine(std::istream & str) +template T getIntLine(int fd) { - string s; + string s = readLine(fd); T res; - getline(str, s); - if (!str || !string2Int(s, res)) throw Error("integer expected from stream"); + if (!string2Int(s, res)) throw Error("integer expected from stream"); return res; } @@ -552,10 +545,8 @@ bool LocalStore::hasSubstitutes(const Path & path) foreach (Paths::iterator, i, substituters) { RunningSubstituter & run(runningSubstituters[*i]); startSubstituter(*i, run); - - *run.to << "have\n" << path << "\n" << std::flush; - - if (getIntLine(*run.from)) return true; + writeLine(run.to, "have\n" + path); + if (getIntLine(run.from)) return true; } return false; @@ -568,19 +559,19 @@ bool LocalStore::querySubstitutablePathInfo(const Path & substituter, RunningSubstituter & run(runningSubstituters[substituter]); startSubstituter(substituter, run); - *run.to << "info\n" << path << "\n" << std::flush; - - if (!getIntLine(*run.from)) return false; + writeLine(run.to, "info\n" + path); + + if (!getIntLine(run.from)) return false; - getline(*run.from, info.deriver); + info.deriver = readLine(run.from); if (info.deriver != "") assertStorePath(info.deriver); - int nrRefs = getIntLine(*run.from); + int nrRefs = getIntLine(run.from); while (nrRefs--) { - Path p; getline(*run.from, p); + Path p = readLine(run.from); assertStorePath(p); info.references.insert(p); } - info.downloadSize = getIntLine(*run.from); + info.downloadSize = getIntLine(run.from); return true; } diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index 1cacfee33..a422af398 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -3,8 +3,6 @@ #include -#include - #include "store-api.hh" #include "util.hh" @@ -36,15 +34,10 @@ struct OptimiseStats }; -typedef __gnu_cxx::stdio_filebuf stdio_filebuf; - - struct RunningSubstituter { Pid pid; - boost::shared_ptr toBuf, fromBuf; - boost::shared_ptr to; - boost::shared_ptr from; + AutoCloseFD to, from; };