rscada / libmbus

Meter-bus library and utility programs
http://www.rscada.se/libmbus
BSD 3-Clause "New" or "Revised" License
217 stars 137 forks source link

Minor bugfixes #67

Closed lategoodbye closed 10 years ago

lategoodbye commented 10 years ago
rscada commented 10 years ago

Why do you prefer to use the current tty settings rather that starting from a known state and setting up the termios options you want? I usually prefer starting from a zeroed termios because otherwise the program might succeed or fail depending on the state of the termios before the program started, which can be hard to troubleshoot if it happens.

lategoodbye commented 10 years ago

I've read that the tty settings are platform dependant and zeroing the termios structure could also leads to a unclear behavior over all platforms until all the necessary flags are set.

I've experienced this problem on another project. The termios structure was zeroed and only a few flags were set. On PC the program works well, but after cross compiling the program for ARM doesn't receive any byte. The final solution was to set the necessary flags.

I think none of both solutions (zero settings nor current settings) are perfect. But the solution with the current settings is also used in the Serial Programming Guide for POSIX Operating Systems from Michael Sweet.

The problem you describe shouldn't happen if all the flags are set or cleared correctly.

rscada commented 10 years ago

I agree that setting all flags explicitly is a good idea when possible, but I still think it would be better keep the memset call as well, unless you are really really sure that you set all relevant flags. For example, in your PR you do not set all the c_cc fields. What if some other tty application modified those? It could give inconsistent results.. I've seen such errors in the past, and they are difficult to debug, so I would be in favor of keeping the memset call. If all fields are set as you claim, then having the memset call should not effect platform compatibility.

lategoodbye commented 10 years ago

Okay, i put back the memset call, but it's untested.