#323 FIONREAD ioctl should not be used (32-bit vs 64-bit systems)

trunk
open
Brian Gerkey
player (137)
5
2012-12-16
2010-02-12
Paul Osmialowski
No

Recently, while porting my old program to 64-bit system I was paying attention on each variable of long type. Pointer to one of them was passed as a parameter to FIONREAD ioctl that I used to check if data are waiting on serial port. I was curious how this is implemented on 64--bit Unixes. What I found was real mess! Namely, see this document: http://www.feyrer.de/PGC/Fighting_the_Lemmings.pdf (page 8 and 9 section Ioctl Calls there's FIONREAD example of troublemaking ioctl call). What I did in my program was to replace it with use of select(), which is more portable. Fortunately, FIONREAD is used only in one place in whole Player tree: /server/drivers/mixed/rflex/rflex-io.cc (that's why it includes sys/filio.h when it is available, FIONREAD is defined there on some Unixes). Now we have few options:
1. Pretend there's no problem
2. Disable it on 64-bit systems (if only cmake is capable to detect 64-bit system!)
3. Rewrite it to use select() instead of FIONREAD ioctl (well, I don't know how clear_incoming_data() function that uses FIONREAD indirectly should be reimplemented then). Since I do not have RWI RFLEX robot myself, I can't do that, I'm not going to publish untested code that talks to the hardware!

Discussion

  • Rich Mattes
    Rich Mattes
    2010-02-15

    CMake already checks for a 64bit host architecture to determine which directory to install libraries to. FindOS.cmake sets a var called PLAYER_PROC_64BIT if the OS is Linux and the host arch is x86_64 or ppc64. You could probably add a check in CMakeLists.txt for the rflex to disable builds on 64 bit systems (option 2).