Note that there are some explanatory texts on larger screens.

plurals
  1. POboost asio taking 100% cpu on read
    text
    copied!<p>i made a socket app that uses boost asio how ever it seems to take a lot of cpu when i try to read any thing from the socket.</p> <p>Atm i use a wrapper class so i dont have to expose the boost header files in my header file that looks something like this:</p> <pre><code>class SocketHandle { public: SocketHandle() { m_pSocket = NULL; m_pService = NULL; } ~SocketHandle() { delete m_pSocket; delete m_pService; } void connect(const char* host, const char* port) { if (m_pSocket || m_pService) return; m_pService = new boost::asio::io_service(); tcp::resolver resolver(*m_pService); tcp::resolver::query query(tcp::v4(), host, port); tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); tcp::resolver::iterator end; m_pSocket = new tcp::socket(*m_pService); boost::system::error_code error = boost::asio::error::host_not_found; while (error &amp;&amp; endpoint_iterator != end) { (*m_pSocket).close(); (*m_pSocket).connect(*endpoint_iterator++, error); } if (error) throw ... } tcp::socket* operator-&gt;() { return m_pSocket; } private: tcp::socket *m_pSocket; boost::asio::io_service *m_pService; }; </code></pre> <p>and then im reading from the socket like so:</p> <pre><code>size_t recv(char *data, size_t size) { boost::system::error_code error; size_t len = (*m_pSocket)-&gt;read_some(boost::asio::buffer(data, size), error); if (error) throw ... return len; } </code></pre> <p>Am i doing something wrong? Is there a better way to read data from the socket?</p> <p>Boost 1.39.0 visual c++ windows</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload