Opened 12 years ago

Last modified 10 years ago

#5339 new Bugs

asio async_read throws boost::asio::error::invalid_argument on mac OS X

Reported by: wjwwood@… Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.45.0 Severity: Problem
Keywords: asio invalid_argument mac os x async_read Cc: wjwwood@…

Description

I am trying to write a serial library using Boost's asio, but on mac OS X the async_read throws boost::asio::error::invalid_argument. I have created a custom completion condition to ignore the invalid_argument exceptions, but this causes a busy wait (using a lot of cpu time) yet does not prevent data from being read.

I have attached source code and output from both linux and os x.

Linux: Ubuntu 10.10 i386 - Boost 1.42.0 Mac OS X: 10.6.6 - Boost 1.45.0

Attachments (5)

serial.cpp (11.9 KB ) - added by wjwwood@… 12 years ago.
serial.h (11.8 KB ) - added by wjwwood@… 12 years ago.
test_serial.cpp (1.3 KB ) - added by wjwwood@… 12 years ago.
osx.transcript (1.0 KB ) - added by wjwwood@… 12 years ago.
linux.transcript (563 bytes ) - added by wjwwood@… 12 years ago.

Download all attachments as: .zip

Change History (14)

by wjwwood@…, 12 years ago

Attachment: serial.cpp added

by wjwwood@…, 12 years ago

Attachment: serial.h added

by wjwwood@…, 12 years ago

Attachment: test_serial.cpp added

by wjwwood@…, 12 years ago

Attachment: osx.transcript added

by wjwwood@…, 12 years ago

Attachment: linux.transcript added

comment:1 by anonymous, 12 years ago

Just a bit more info...

The Linux transcript is the expected behavior. The characters are coming into the serial port at 1Hz (Arduino microcontroller) and the timeout is set to 250 milliseconds, so there should be three time outs to every read with data.

The problem seems to allow data to be read on os x, but it prevents serial_port.cancel from working properly and therefore keeping my deadline_timer based timeout from working properly.

The serial.h and serial.cpp should compile with just Boost, but the test_serial.cpp uses ROS (ros.org), but the example is simple enough to reproduce with out quickly.

comment:2 by chris_kohlhoff, 12 years ago

Try adding -DBOOST_ASIO_DISABLE_KQUEUE to your compiler command line to disable kqueue.

Apparently, character devices residing on an HFS partition are incompatible with kqueue. See this forum post for example.

Please consider raising a bug with Apple if this is important to you.

comment:3 by anonymous, 12 years ago

Thanks this seems to allow expected behavior in OS X. I had two follow up questions though.

  1. Does disabling kqueue for a select based implementation have many if any drawbacks? (Is this documented somewhere?)
  2. Would you advise define'ing the BOOST_ASIO_DISABLE_KQUEUE in the compiler arguments or in the source code?

Sorry if these seems like easy questions, I am still a bit new to c++ and boost.

Thanks!

in reply to:  3 comment:4 by chris_kohlhoff, 12 years ago

Replying to anonymous:

  1. Does disabling kqueue for a select based implementation have many if any drawbacks? (Is this documented somewhere?)

If you use select then "the number of file descriptors in the process cannot be permitted to exceed FD_SETSIZE". This defaults to 1024 on Mac OS X.

(From http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/overview/implementation.html)

  1. Would you advise define'ing the BOOST_ASIO_DISABLE_KQUEUE in the compiler arguments or in the source code?

You should prefer the compiler command line for these sorts of options. It helps ensure the option is consistent across your whole program.

comment:5 by anonymous, 11 years ago

Could you add a note about this to the Mac OS X platform-specific implementation notes? This is the first place I looked when this bit me. I wouldn't have wasted a bunch of time on it if it were already documented.

comment:6 by Pharmb679, 10 years ago

Hello! ggacbad interesting ggacbad site! I'm really like it! Very, very ggacbad good!

comment:7 by Pharmd821, 10 years ago

Hello! cfdeeef interesting cfdeeef site! I'm really like it! Very, very cfdeeef good!

comment:8 by Pharmc743, 10 years ago

Hello! gddfbdd interesting gddfbdd site! I'm really like it! Very, very gddfbdd good!

comment:9 by Pharme273, 10 years ago

Hello! kbbaeea interesting kbbaeea site! I'm really like it! Very, very kbbaeea good!

Note: See TracTickets for help on using tickets.