summaryrefslogtreecommitdiff
path: root/cpp/src/IceGrid/Parser.cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2006-12-07 12:26:16 +0000
committerBenoit Foucher <benoit@zeroc.com>2006-12-07 12:26:16 +0000
commit687eda4d1d6ab70e67c626a4cfa83e73672c5001 (patch)
treef1569d083da5e1691793b4ddb7d08c11cf447c2f /cpp/src/IceGrid/Parser.cpp
parentMade DEBUG the default build setting. (diff)
downloadice-687eda4d1d6ab70e67c626a4cfa83e73672c5001.tar.bz2
ice-687eda4d1d6ab70e67c626a4cfa83e73672c5001.tar.xz
ice-687eda4d1d6ab70e67c626a4cfa83e73672c5001.zip
Improved FileIterator interface Changed patch() operation on the node to
use a callback object.
Diffstat (limited to 'cpp/src/IceGrid/Parser.cpp')
-rw-r--r--cpp/src/IceGrid/Parser.cpp114
1 files changed, 40 insertions, 74 deletions
diff --git a/cpp/src/IceGrid/Parser.cpp b/cpp/src/IceGrid/Parser.cpp
index ff7fbfa1e91..74b4b9b292e 100644
--- a/cpp/src/IceGrid/Parser.cpp
+++ b/cpp/src/IceGrid/Parser.cpp
@@ -1324,60 +1324,62 @@ Parser::dumpFile(const string& reader, const string& filename, const list<string
try
{
string id = *(args.begin());
+
+ cout << reader << " `" << id << "' " << filename << ": " << flush;
+ Ice::StringSeq lines;
+
+ bool head = opts.isSet("head");
+ bool tail = opts.isSet("tail");
+ if(head && tail)
+ {
+ invalidCommand("can't specify both -h | --head and -t | --tail options");
+ return;
+ }
+ int lineCount = 20;
+ const int maxBytes = 512 * 1024;
+ if(head || tail)
+ {
+ istringstream is(head ? opts.optArg("head") : opts.optArg("tail"));
+ is >> lineCount;
+ if(lineCount <= 0)
+ {
+ invalidCommand("invalid argument for -h | --head or -t | --tail option");
+ return;
+ }
+ }
+
FileIteratorPrx it;
if(reader == "node")
{
if(filename == "stderr")
{
- it = _session->openNodeStdErr(id);
+ it = _session->openNodeStdErr(id, tail ? lineCount : -1);
}
else if(filename == "stdout")
{
- it = _session->openNodeStdOut(id);
+ it = _session->openNodeStdOut(id, tail ? lineCount : -1);
}
}
else if(reader == "registry")
{
if(filename == "stderr")
{
- it = _session->openRegistryStdErr(id);
+ it = _session->openRegistryStdErr(id, tail ? lineCount : -1);
}
else if(filename == "stdout")
{
- it = _session->openRegistryStdOut(id);
+ it = _session->openRegistryStdOut(id, tail ? lineCount : -1);
}
}
else if(reader == "server")
{
if(filename == "stderr")
{
- it = _session->openServerStdErr(id);
+ it = _session->openServerStdErr(id, tail ? lineCount : -1);
}
else if(filename == "stdout")
{
- it = _session->openServerStdOut(id);
- }
- }
-
- cout << reader << " `" << id << "' " << filename << ": " << flush;
- Ice::StringSeq lines;
-
- bool head = opts.isSet("head");
- bool tail = opts.isSet("tail");
- if(head && tail)
- {
- invalidCommand("can't specify both -h | --head and -t | --tail options");
- return;
- }
- int lineCount = 20;
- if(head || tail)
- {
- istringstream is(head ? opts.optArg("head") : opts.optArg("tail"));
- is >> lineCount;
- if(lineCount <= 0)
- {
- invalidCommand("invalid argument for -h | --head or -t | --tail option");
- return;
+ it = _session->openServerStdOut(id, tail ? lineCount : -1);
}
}
@@ -1392,63 +1394,26 @@ Parser::dumpFile(const string& reader, const string& filename, const list<string
}
int i = 0;
- while(!interrupted())
- {
- lines = it->read(20);
-
- Ice::StringSeq::const_iterator p = lines.begin();
- while(i < lineCount && p != lines.end())
- {
- cout << endl << *p++ << flush;
- ++i;
- }
-
- if(i == lineCount || lines.size() < 20)
- {
- break;
- }
- }
- }
- else if(tail)
- {
- deque<string> lastLines;
- while(!interrupted())
+ bool eof = false;
+ while(!interrupted() && !eof && i < lineCount)
{
- lines = it->read(20);
-
- copy(lines.begin(), lines.end(), back_inserter(lastLines));
- int remove = lastLines.size() - lineCount;
- if(remove > 0)
+ eof = it->read(20, maxBytes, lines);
+ for(Ice::StringSeq::const_iterator p = lines.begin(); i < lineCount && p != lines.end(); ++p, ++i)
{
- lastLines.erase(lastLines.begin(), lastLines.begin() + remove);
- assert(lastLines.size() == static_cast<unsigned int>(lineCount));
- }
-
- if(lines.size() < 20)
- {
- break;
+ cout << endl << *p << flush;
}
}
-
- for(deque<string>::const_iterator p = lastLines.begin(); p != lastLines.end(); ++p)
- {
- cout << endl << *p << flush;
- }
}
else
{
- while(!interrupted())
+ bool eof = false;
+ while(!interrupted() && !eof)
{
- lines = it->read(20);
+ eof = it->read(20, maxBytes, lines);
for(Ice::StringSeq::const_iterator p = lines.begin(); p != lines.end(); ++p)
{
cout << endl << *p << flush;
}
-
- if(lines.size() < 20)
- {
- break;
- }
}
}
@@ -1456,7 +1421,7 @@ Parser::dumpFile(const string& reader, const string& filename, const list<string
{
while(!interrupted())
{
- lines = it->read(20);
+ bool eof = it->read(20, maxBytes, lines);
for(Ice::StringSeq::const_iterator p = lines.begin(); p != lines.end(); ++p)
{
cout << *p;
@@ -1470,6 +1435,7 @@ Parser::dumpFile(const string& reader, const string& filename, const list<string
}
}
+ if(eof)
{
Lock sync(*this);
if(_interrupted)