Opened 8 years ago

Closed 8 years ago

#4782 closed Bugs (fixed)

ioctl constants are sign extended on 64 bit builds

Reported by: arvid@… Owned by: chris_kohlhoff
Milestone: Boost 1.45.0 Component: None
Version: Boost 1.44.0 Severity: Regression
Keywords: Cc:


Sometime between boost 1.40 and 1.44 asio started to keep track of whether or not the user had set the FIONBIO ioctl (non blocking I/O). On a 64 bit build this test fails, and asio believes that the socket is still in blocking mode. The reason why it fails is because the constants defined are unsigned ints, in asio's io control wrapper template, the "name" is returned as an int. This is later cast to a long and then compared to the system constants.

The problem is that the system constants, although they fit in a 32 bit value, have the most significant bit set, so the cast from int -> long causes sign extension, and the comparison to the FIONBIO constant always fails.

The fix for this is quite simple; in the file boost/asio/detail/io_control.hpp, just change the return value of non_blocking_io::name() to be a long instead of an int.

asio seems to be using longs in the socket_ops.hpp for its ioctl() wrapper, so this seems like the most appropriate solution. This goes for all classes implementing the IoControlCommand? concept.

I marked this as a regression, but it might make sense to consider it a show-stopper, because it means any application that relies on non-blocking operations will freeze. On Mac OS X, 64 bit builds are defaults, so all mac applications are affected.

I tried to post this to the mailing list with a few more details a few weeks ago, but I don't think it made it through.

Change History (3)

comment:1 Changed 8 years ago by chris_kohlhoff

Hmm, I might have already fixed this when making changes for NetBSD. Can you please try changeset [66162].

comment:2 Changed 8 years ago by arvid@…

I haven't had time to personally test this patch yet, but Adam Fisk reported on the libtorrent mailing list that it fixed the issue for him.

comment:3 Changed 8 years ago by chris_kohlhoff

Resolution: fixed
Status: newclosed

Ok, thanks. Added to release notes for 1.45.

Note: See TracTickets for help on using tickets.