开发者

How does Boost ASIO receive_from return underlying socket errors?

开发者 https://www.devze.com 2023-01-19 04:09 出处:网络
i.e. will the blocking version return -1 on error. Or more to the point, how do you know the call failed?does

i.e. will the blocking version return -1 on error.

Or more to the point, how do you know the call failed? does

boost::asio::ip::udp::socket::receive_from() return -1 on error

The normal BSD socket API receive_from call will return -1 on errors and you can look at errno for the specific error code. Does the boost version do the same?

Ok, I tried passing the overload like this:

while(true){
    boost::system::error_code ec;
    size_t length = socket_.receive_from(
        boost::asio::buffer(buffer, buffer_size), 
        sender_endpoint, ec);

    /// ... other code
}

But I get this err开发者_运维问答or on compilation:

error: no matching function for call to ‘boost::asio::basic_datagram_socket<boost::asio::ipdp, boost::asio::datagram_socket_service<boost::asio::ip::udp> >::receive_from(boost::asio::mutable_buffer, boost::asio::ip::basic_endpoint<boost::asio::ip::udp>&, boost::system::error_code&)’
make: *** [server.o] Error 1

Is the documentation wrong or am I doing something wrong? EDIT: no I'm wrong... sorry I'm having a moment... it's called overwork! I'm half asleep right now. I'm missing the flags argument.


It throws a boost::system::system_error exception on failure. There's an overload taking a parameter if you don't want to handle the exception.

0

精彩评论

暂无评论...
验证码 换一张
取 消