Boost logo

Boost :

From: Felipe Magno de Almeida (felipe.m.almeida_at_[hidden])
Date: 2005-12-12 16:42:17


On 12/12/05, Christopher Kohlhoff <chris_at_[hidden]> wrote:
> Hi Felipe,
>
> --- Felipe Magno de Almeida <felipe.m.almeida_at_[hidden]> wrote:
> <snip>

[snip]

>
> This could be done by composing a new function object to be
> passed as the handler, e.g.:
>
> async_read(s, buffers,
> combine_handlers(handler1, handler2));
>
> Boost.Lambda may also be of some use here.
>
> However I am not convinced that this approach would be widely
> applicable. There are many cases in networking where an error
> for an individual operation is not an error for the application.

What I mean is to be able to have like two member functions in a
class, one for handling an error in the read operation, and other for
handling the correct case.

>
> I also see the current "exactly-once" semantics of invoking
> handlers as important in aiding correct program design, so I'd
> be wary of using anything that changed that.

Didnt understood what you meant...
You think every functor should be executed exactly-once for correct
program design?
Wouldnt this still be safe?

class handler
{
  void fail(asio::error err)
  {
    // handle the error case, and probably delete this handle, or
reuse it for retrying
  }

  void success(int size)
  {
    // do something, or continue reading or delete this
  }
// member variables

public:
  handler()
  {
    async_read(s, buffers,
      combine_handlers(
        boost::bind(boost::mem_fn(&handler::success), this)
        , boost::bind(boost::mem_fn(&handler::fail), this)
      ));
  }
};

>
> Cheers,
> Chris
>

Thanks,

--
Felipe Magno de Almeida

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