[Bro-Dev] Rethinking Broker's blocking API

Robin Sommer robin at icir.org
Fri Jan 6 05:16:38 PST 2017



On Thu, Jan 05, 2017 at 17:04 -0800, you wrote:

>     expected<message> receive();

Yeah, I like that, except for one concern:

> switch (msg.error()) {
>       default:
>         cout << to_string(msg.error()) << endl;
>         break;
>       case status::peer_added:
>         cout << "got new peer: " << msg.context() << endl;
>         break;
>       case status::peer_lost::
>         break;
>     }

I think the name "error" is not just misleading but would also turn
out tricky to use correctly. In that switch statement, if the default
case is to handle only (real) errors, one would need to fully
enumerate all the status:* messages so that they don't arrive there
too. More generally: the distinction between errors that signal
trouble with the connection and expected state changes doesn't come
through here.

What do you think about adding two methods instead of one to allow
differentiating between status updates and errors explicitly: status()
returns a joined result code like your error(); and failed() returns a
boolean indicating if that status reflects an error situation:

    auto msg = ep.receive();

    if (msg)
        return f(*msg); // unbox contained message

    if (msg.failed())
        cout << "Trouble: " << to_string(msg.status()) << endl;
    else
        cout << "Status change: " << to_string(msg.status()) << endl;

In either case one could then also use a switch to differentiate the
status() further.

Robin

-- 
Robin Sommer * ICSI/LBNL * robin at icir.org * www.icir.org/robin


More information about the bro-dev mailing list