Boost logo

Boost :

From: Cory Nelson (phrosty_at_[hidden])
Date: 2005-12-12 07:30:57


On 12/12/05, Felipe Magno de Almeida <felipe.m.almeida_at_[hidden]> wrote:
> On 12/12/05, Cory Nelson <phrosty_at_[hidden]> wrote:
>
> [snip]
>
> >
> > For the API, one thing that struck me is the almost C-style error
> > handling. I believe the .NET way is better. It provides a point that
> > the developer must call to get the result of the operation, and that
> > the sockets can throw any exceptions that would normally be thrown in
> > sync operations.
> >
> > [snip]
>
> Could you elaborate a little more about what you mean with C-style
> error handling and the error handling you prefer (.NET) ?

In the current asio implementation, a handler looks like this:

void on_recv(const asio::error &err, size_t len) {
   if(!err) { ... }
   else { ... }
}

In .NET, a handler looks like this:

void on_recv(IAsyncResult res) {
   int len;
   try { len=sock.EndRecv(res); }
   catch(SocketException ex) { ...; return; }

   ...
}

The key difference is that asio allows you to check the error but
doesn't force it.

In .NET, EndRecv *must* be called to get the result of the operation.
A result either being a valid return or an exception. By forcing
accountability it plugs a reliability hole.

An added benefit of this is that calling an End* method in .NET will
block if the operation isn't finished, so that option is there if you
need it.

Nearly all of the STL (the only exception I can immediately think of
being streams) throws exceptions on error, why should asio break from
the norm?

> [snip]
>
> > Async connecting does not use ConnectEx on platforms which support it.
> > This isn't such a big issue, but it's still a disappointment.
>
> I agree, ConnectEx is very good. I wouldnt say a disappointment
> though, it is very easy to integrate this to the library.
>
> [snip]
>
> >
> > --
> > Cory Nelson
> > http://www.int64.org
> >
>
> best regards,
> --
> Felipe Magno de Almeida
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>

--
Cory Nelson
http://www.int64.org

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk