
I'm trying to implement a non_blocking read as follows (based on some code on the net): void util::net::set_result(optional<boost::system::error_code>* a, boost::system::error_code b) { a->reset(b); } template <typename MutableBufferSequence> optional<boost::system::error_code> util::net::read_non_blocking(ip::tcp::socket *sock, const MutableBufferSequence& buffers, int timeoutSec) { optional<boost::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)); optional<boost::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::optional<boost::system::error_code> util::net::read_non_blocking<boost::asio::mutable_buffers_1>(boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >*, boost::asio::mutable_buffers_1 const&, int) Also, what will this code return exacty?