Boost logo

Boost Users :

Subject: [Boost-users] [asio] UDP recv error handling
From: Klebsch, Mario (Mario.Klebsch_at_[hidden])
Date: 2018-11-22 14:44:33


Hello,

When using boos asio async receiving, my received callback usually looks like this:

void ReceiveCB(const boost::system::error_code& error, std::size_t bytes_transferred)
{
                If (error) {
                               fprintf(stderr, "recv() failes: %s\n", error.message().c_str());
                               return;
                }

                /* process data received */

                s.async_receive( boost::asio::buffer(...), & ReceiveCB);
}

I stop calling async_receive() as soon as I get an error. This works good for TCP sockets.

But with UDP sockets, recvfrom() can return e.g. the error 'connection refused' after I called sendto() to a peer machine, where no socket is (yet) bound to the destination port number. So, at least after the error 'connection refuxed', I'd better continue calling async_receive_from().

Are there any recommendations on how to decide, whether the receive callback function should re-initiate a receive operation after a receive error or not?

Mario Klebsch

--
Mario Klebsch                      Actia I+ME GmbH
Mario.klebsch_at_[hidden]<mailto:Mario.klebsch_at_[hidden]>         Dresdenstrasse 17/18
Fon: +49 531 38 701 716            38124 Braunschweig
Fax: +49 531 38 701 88            Germany


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net