diff options
author | Denis Shienkov <scapig@yandex.ru> | 2012-05-14 16:02:02 +0400 |
---|---|---|
committer | Denis Shienkov <scapig@yandex.ru> | 2012-05-14 14:58:40 +0200 |
commit | 77ab1d775ade00bb39ddb04949f728e20bfa2a8a (patch) | |
tree | cf68bfff19f133a831282d9eaa5b1c4abc78a7c6 | |
parent | bc7b8743b63a7aa3c5c3b28ed58fc5b31b623419 (diff) | |
download | qtserialport-77ab1d775ade00bb39ddb04949f728e20bfa2a8a.tar.gz |
On *nix, fix getting count of bytes in the input/output queue.
Valid value of number of bytes available only on the condition that
the driver of the serial port supports this feature. In the others
cases will be returned a zero or -1.
Change-Id: Ieb036d044838f9c3b53ff6a331d4bbeea01790e2
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Denis Shienkov <scapig@yandex.ru>
-rwxr-xr-x | src/serialportengine_unix.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/serialportengine_unix.cpp b/src/serialportengine_unix.cpp index d54a518..02156f2 100755 --- a/src/serialportengine_unix.cpp +++ b/src/serialportengine_unix.cpp @@ -428,31 +428,31 @@ bool UnixSerialPortEngine::setBreak(bool set) } /*! - If successful, returns the number of bytes that are - immediately available for reading; otherwise -1. + If successful, returns the number of bytes in + the input buffer; otherwise -1. */ qint64 UnixSerialPortEngine::bytesAvailable() const { - int cmd = 0; -#if defined (FIONREAD) - cmd = FIONREAD; -#else - cmd = TIOCINQ; -#endif - qint64 nbytes = 0; - if (::ioctl(m_descriptor, cmd, &nbytes) == -1) + int nbytes = 0; +#if defined (TIOCINQ) + if (::ioctl(m_descriptor, TIOCINQ, &nbytes) == -1) return -1; +#endif return nbytes; } /*! - Not supported on POSIX-compatible platforms, - always returns 0. + If successful, returns the number of bytes in + the output buffer; otherwise -1. */ qint64 UnixSerialPortEngine::bytesToWrite() const { - // FIXME: FIONWRITE (or analogy) is exists? - return 0; + int nbytes = 0; +#if defined (TIOCOUTQ) + if (::ioctl(m_descriptor, TIOCOUTQ, &nbytes) == -1) + return -1; +#endif + return nbytes; } /*! |