rendered paste bodybool QSerialPort::waitForReadyRead(int msecs)
{
#ifdef USE_POSIX_SYSCALLS
struct timeval tv;
fd_set readSet;
if ( d->fd != -1 ) {
tv.tv_sec = msecs / 1000;
tv.tv_usec = msecs * 1000;
FD_ZERO( &readSet );
FD_SET( d->fd, &readSet );
return ( select( d->fd + 1, &readSet, 0, 0, &tv ) > 0 );
} else {
return false;
}
#else
return false;
#endif
}
/*!
\reimp
*/
qint64 QSerialPort::bytesAvailable() const
{
#ifdef USE_POSIX_SYSCALLS
if ( d->fd != -1 ) {
// See comments in Qt4's qsocketlayer_unix.cpp for the reason
// why this ioctl call sequence is a little bizarre in structure.
size_t nbytes = 0;
qint64 available = 0;
if (::ioctl( d->fd, FIONREAD, (char *) &nbytes ) >= 0)
available = (qint64) *((int *) &nbytes);
return available;
} else {
return 0;
}
#else
return 0;
#endif
}
/*!
\reimp
*/
qint64 QSerialPort::readData( char *data, qint64 maxlen )
{
#ifdef USE_POSIX_SYSCALLS
int result;
if ( d->fd == -1 ) {
return -1;
}
while ( ( result = ::read( d->fd, data, (int)maxlen ) ) < 0 ) {
if ( errno != EINTR ) {
if ( errno == EWOULDBLOCK ) {
return 0;
}
qLog(Modem) << "read errno = " << errno;
return -1;
}
}
if ( !result && ( !d->isTty || ( !d->keepOpen && !dsr() ) ) ) {
// We've received a close notification. This might happen
// with the phone simulator if it is shut down before Qtopia.
// Don't do this for tty devices because there are some systems
// that return zero when they should be returning EWOULDBLOCK.
qLog(Modem) << "QSerialPort::readData: other end closed the connection" ;
close();
}
//data[strlen(data)-1]=0x0;
return result;
//return result;
#else
return -1;
#endif
}