]> git.puffer.fish Git - matthieu/frr.git/commit
lib: Add STREAM_GETX functions
authorDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 2 Nov 2017 12:37:06 +0000 (08:37 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Mon, 13 Nov 2017 19:15:24 +0000 (14:15 -0500)
commit051cc28c8f586eb3482e5fd9878b2307dbf98e38
tree09f3c9e167bf48c72e7058e3c707ff4593d933d2
parent4df759fecf7cf2b6cd45e47789e8d06437ff7ca7
lib: Add STREAM_GETX functions

Currently when stream reads fail, for any reason, we assert.
While a *great* debugging tool, Asserting on production code
is not a good thing.  So this is the start of a conversion over
to a series of STREAM_GETX functions that do not assert and
allow the developer a way to program this gracefully and still
clean up.

Current code is something like this( taken from redistribute.c
because this is dead simple ):

afi = stream_getc(client->ibuf);
type = stream_getc(client->ibuf);
instance = stream_getw(client->ibuf);

This code has several issues:

1) There is no failure mode for the stream read other than assert.
if afi fails to be read the code stops.
2) stream_getX functions cannot be converted to a failure mode
because it is impossible to tell a failure from good data
with this api.

So this new code will convert to this:

STREAM_GETC(client->ibuf, afi);
STREAM_GETC(client->ibuf, type);
STREAM_GETW(client->ibuf, instance);

....

stream_failure:
return;

We've created a stream_getc2( which does not assert ),
but we need a way to allow clean failure mode handling.
This is done by macro'ing stream_getX2 functions with
the equivalent all uppercase STREAM_GETX functions that
include a goto.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
lib/stream.c
lib/stream.h