Opened 9 years ago

Closed 9 years ago

#2835 closed Bugs (wontfix)

basic_stream_socket::available() does not work reliably

Reported by: sidharth@… Owned by: chris_kohlhoff
Milestone: Boost 1.39.0 Component: asio
Version: Boost 1.38.0 Severity: Problem
Keywords: Cc:


basic_stream_socket::available() often reports 0 bytes even when there is data available to be read.

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).

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.

I realize the root cause is a Microsoft issue, but it's a boost asio bug at the end of the day.

Attachments (0)

Change History (3)

comment:1 Changed 9 years ago by Steven Watanabe

Component: Noneasio
Owner: set to chris_kohlhoff

comment:2 Changed 9 years ago by anonymous

I forgot to mention that:

  • this works fine on Linux (I have run my test hundreds of times without failures)
  • I encountered this issue with boost 1.37 (a quick review showed that 1.38's implementation of available() uses ioctlsocket() as well.)


comment:3 Changed 9 years ago by chris_kohlhoff

Resolution: wontfix
Status: newclosed

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.

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.

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.

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain chris_kohlhoff.
The resolution will be deleted.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.