[Botan-devel] Re: [Monotone-devel] oprofile data for mtn 0.37.

Jack Lloyd lloyd at randombit.net
Thu Mar 13 11:08:19 EDT 2008


On Thu, Mar 13, 2008 at 10:41:11AM -0400, Zack Weinberg wrote:
>   for (;;)
>     {
>       getline(cin, buf);
>       if (cin.eof()) break;
>       cout << '[' << buf << ']' << '\n';
>       p.process_msg(buf);
>       cout << '|' << (p.read_all_as_string()) << '|' << '\n';
>     }
> }
> 
> which only produces the SHA1 hash of the first line of input; the
> intent is to hash each line separately.

Pipe actually keeps each message around forever (all storage is
reclaimed once a) all output has been read out b) the message in
question is not currently being processed). You can read out a out of
order / interleaved with reading others / whatever.

pipe.process_msg(msg1);
pipe.process_msg(msg2);
pipe.process_msg(msg3);

// now read output of msg2 | pipe
... = pipe.read_all_as_string(1);

The second argument to all of the Pipe::read_* functions is a 32-bit
message number. This can be 0...n (the first message run through a
Pipe is 0, etc), or Pipe::LAST_MESSAGE or Pipe::DEFAULT_MESSAGE.

LAST_MESSAGE is the most recent message processed. DEFAULT_MESSAGE
means use the value set/returned by Pipe::default_msg() /
Pipe::get_default_msg(), and it is DEFAULT_MESSAGE which is the
default value of the second paramter. Initially, DEFAULT_MESSAGE is 0,
which is why you get no output after the first read -- the Pipe is
always looking in msg 0, which is empty after the first call to
read_all_as_string.

       cout << '|' << (p.read_all_as_string(Pipe::LAST_MESSAGE)) << '|' << '\n';

The default for those functions really should be LAST_MESSAGE --
DEFAULT_MESSAGE is actually not very useful IMO, and tends to be a
point of confusion (including for me). It is only that way because
(for whatever reason) I only though of / implemented LAST_MESSAGE
after, and didn't want to break compat.

-Jack



More information about the botan-devel mailing list