
I'm trying to implement a non_blocking read as follows (based on some
code on the net):
void util::net::set_result(optionalboost::system::error_code* a,
boost::system::error_code b)
{
a->reset(b);
}
template <typename MutableBufferSequence>
optionalboost::system::error_code
util::net::read_non_blocking(ip::tcp::socket *sock, const
MutableBufferSequence& buffers, int timeoutSec)
{
optionalboost::system::error_code timer_result;
deadline_timer timer(sock->io_service());
timer.expires_from_now(boost::posix_time::seconds(timeoutSec));
timer.async_wait(boost::bind(set_result, &timer_result, _1));
optionalboost::system::error_code read_result;
async_read(*sock, buffers,
boost::bind(set_result, &read_result, _1));
sock->io_service().reset();
while (sock->io_service().run_one())
{
if (read_result)
timer.cancel();
else if (timer_result) {
sock->cancel();
throw system_error(boost::system::error_code(errc::timed_out,
get_generic_category()));
}
}
return read_result;
}
I call the code as follows:
util::net::read_non_blocking(Module::_socket, buffer(buf, 4), 1);
(_socket is a ptr of type tcp::socket)
However I'm having problems linking:
undefined reference to `boost::optionalboost::system::error_code
util::net::read_non_blockingboost::asio::mutable_buffers_1(boost::asio::basic_stream_socket