title: io_service::run() never returns
body: <p><strong>UPDATE_2</strong>
  I ended up using</p>
  
  <pre><code>if (socket.available())
  </code></pre>
  
  <p>If there is data on the socket, I read it and if not, I skip.</p>
  
  <p><strong>UPDATED</strong>
  I have a problem. io_service::run() never returns in the following code snippet:</p>
  
  <p>The client side:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  #include &lt;boost/asio.hpp&gt;
  #include &lt;boost/bind.hpp&gt;
  #include &lt;boost/array.hpp&gt;
  
  using namespace std;
  using boost::asio::ip::tcp;
  
  void handler(
      const boost::system::error_code &amp;error,
      size_t bytes_transferred
  )
  {
      cout &lt;&lt; "Handler called" &lt;&lt; endl;
  }
  
  int main()
  {
      //establishing connection
      boost::asio::io_service io_service;
      tcp::socket socket(io_service);
      tcp::resolver resolver(io_service);
      tcp::resolver::query query("localhost", "17073");
      tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
      boost::asio::connect(socket, endpoint_iterator);
      //connection established
  
      boost::array&lt;char, 128&gt; buf;
      socket.async_read_some(boost::asio::buffer(buf), boost::bind(handler, _1, _2));
  
      //async_read_some returns
  
      io_service.run();       //I suppose that handler_for_async_response is called if:
                              //1) EOF was read (no data read twice) by async_read_some
                              //2) something was in fact read
                              //is this right?
  
      //execution does not get here
  
      return 0;
  }
  </code></pre>
  
  <p>The server side(only accepts the connection and hangs there doing nothing):</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;boost/asio.hpp&gt;
  #include &lt;boost/bind.hpp&gt;
  #include &lt;boost/array.hpp&gt;
  
  using namespace std;
  using boost::asio::ip::tcp;
  
  int main()
  {
      //establishing connection
      boost::asio::io_service io_service;
      tcp::socket             socket(io_service);
      tcp::acceptor           acceptor(io_service, tcp::endpoint(tcp::v4(), 17073));
  
      acceptor.accept(socket);
  
      std::cout &lt;&lt; "connection has been established!" &lt;&lt; std::endl;
      //connection established
  
      while (true)
      {
          //do nothing
      }
  
      return 0;
  }
  </code></pre>
  
  <p>What I am trying to do is see if there is any data on the socket. If yes - then read it, if no - then move on.</p>
  
  <p>PS I am planning to both read from the socket and write to it.</p>
  
  <p>Anyway, I am new to boost::asio and I hope someone can tell me what I am doing wrong. Thanks!</p>