I’m new to boost and I’ve been trying out boost::asio. The problem is I always get an “Bad File Descriptor” error/exception when setting some options (I need to make it non-blocking). Even this here fails:
#include <boost/asio.hpp>
using boost::asio::ip::tcp;
int main( )
{
boost::asio::io_service io_service;
tcp::socket socket( io_service );
boost::asio::socket_base::non_blocking_io option(true);
socket.io_control( option );
return 0;
}
During run-time this pops up:
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> >'
what(): Bad file descriptor
Which is getting really frustrating as I’ve tried everything. OS is Linux x64 if it matters.
You invoked the socket constructor that does not open the
socket. You could use one of the other overloads that open thesocketprior to invokingsocket::io_control(), or open thesocketexplicitly.