Boost C++ Libraries: Ticket #2835: basic_stream_socket::available() does not work reliably https://svn.boost.org/trac10/ticket/2835 <p> basic_stream_socket::available() often reports 0 bytes even when there is data available to be read. </p> <p> The implementation of basic_stream_socket::available() for windows uses ioctlsocket() with FIONREAD which Microsoft advises against using. (recv(MSG_PEEK) is not prescribed either). </p> <p> <a class="ext-link" href="http://support.microsoft.com/kb/192599"><span class="icon">​</span>http://support.microsoft.com/kb/192599</a> </p> <p> For clients wanting to poll for available data and then calling a blocking read, barring any other reliable way to peek for data availability, it would be better to have an isavailable() (based on select()) which a client could call before doing a read_some. </p> <p> I realize the root cause is a Microsoft issue, but it's a boost asio bug at the end of the day. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2835 Trac 1.4.3 Steven Watanabe Thu, 05 Mar 2009 23:37:41 GMT component changed; owner set https://svn.boost.org/trac10/ticket/2835#comment:1 https://svn.boost.org/trac10/ticket/2835#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">chris_kohlhoff</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">asio</span> </li> </ul> Ticket anonymous Thu, 05 Mar 2009 23:42:28 GMT <link>https://svn.boost.org/trac10/ticket/2835#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2835#comment:2</guid> <description> <p> I forgot to mention that: </p> <ul><li>this works fine on Linux (I have run my test hundreds of times without failures) </li></ul><ul><li>I encountered this issue with boost 1.37 (a quick review showed that 1.38's implementation of available() uses ioctlsocket() as well.) </li></ul><p> Thanks </p> </description> <category>Ticket</category> </item> <item> <dc:creator>chris_kohlhoff</dc:creator> <pubDate>Thu, 09 Apr 2009 12:32:22 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2835#comment:3 https://svn.boost.org/trac10/ticket/2835#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> How do you know that there is data waiting to be read? If you can construct a test case feel free to reopen this bug. </p> <p> With respect to your "isavailable()" proposal, you already have this facility available using asynchronous reads (with or without using null_buffers) or by setting your socket to non-blocking. </p> <p> N.B The Microsoft KB article is not related to the behaviour you describe. In fact, the article seems to describe ioctl/FIONREAD working as intended. </p> Ticket