diff options
Diffstat (limited to 'src/serialport/qserialport_unix.cpp')
-rw-r--r-- | src/serialport/qserialport_unix.cpp | 72 |
1 files changed, 42 insertions, 30 deletions
diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp index 29822d5..11ab16f 100644 --- a/src/serialport/qserialport_unix.cpp +++ b/src/serialport/qserialport_unix.cpp @@ -204,39 +204,11 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode) return false; } -#ifdef TIOCEXCL - if (::ioctl(descriptor, TIOCEXCL) == -1) - q->setError(decodeSystemError()); -#endif - - if (::tcgetattr(descriptor, &restoredTermios) == -1) { - q->setError(decodeSystemError()); + if (!initialize(mode)) { + qt_safe_close(descriptor); return false; } - currentTermios = restoredTermios; -#ifdef Q_OS_SOLARIS - currentTermios.c_iflag &= ~(IMAXBEL|IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); - currentTermios.c_oflag &= ~OPOST; - currentTermios.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); - currentTermios.c_cflag &= ~(CSIZE|PARENB); - currentTermios.c_cflag |= CS8; -#else - ::cfmakeraw(¤tTermios); -#endif - currentTermios.c_cflag |= CLOCAL; - currentTermios.c_cc[VTIME] = 0; - currentTermios.c_cc[VMIN] = 0; - - if (mode & QIODevice::ReadOnly) - currentTermios.c_cflag |= CREAD; - - if (!updateTermios()) - return false; - - if ((flags & O_WRONLY) == 0) - setReadNotificationEnabled(true); - lockFileScopedPointer.swap(newLockFileScopedPointer); return true; @@ -869,6 +841,46 @@ bool QSerialPortPrivate::completeAsyncWrite() return startAsyncWrite(); } +inline bool QSerialPortPrivate::initialize(QIODevice::OpenMode mode) +{ + Q_Q(QSerialPort); + +#ifdef TIOCEXCL + if (::ioctl(descriptor, TIOCEXCL) == -1) + q->setError(decodeSystemError()); +#endif + + if (::tcgetattr(descriptor, &restoredTermios) == -1) { + q->setError(decodeSystemError()); + return false; + } + + currentTermios = restoredTermios; +#ifdef Q_OS_SOLARIS + currentTermios.c_iflag &= ~(IMAXBEL|IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); + currentTermios.c_oflag &= ~OPOST; + currentTermios.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); + currentTermios.c_cflag &= ~(CSIZE|PARENB); + currentTermios.c_cflag |= CS8; +#else + ::cfmakeraw(¤tTermios); +#endif + currentTermios.c_cflag |= CLOCAL; + currentTermios.c_cc[VTIME] = 0; + currentTermios.c_cc[VMIN] = 0; + + if (mode & QIODevice::ReadOnly) + currentTermios.c_cflag |= CREAD; + + if (!updateTermios()) + return false; + + if (mode & QIODevice::ReadOnly) + setReadNotificationEnabled(true); + + return true; +} + bool QSerialPortPrivate::updateTermios() { Q_Q(QSerialPort); |