[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/kdepim/enterprise4/kdepimlibs/qgpgme
From:       Marc Mutz <mutz () kde ! org>
Date:       2009-10-28 15:22:41
Message-ID: 1256743361.035546.26666.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1041824 by mutz:

QIODeviceDataProvider::read: implement blocking behaviour. Fixes QProcess io devices

 M  +10 -2     dataprovider.cpp  


--- branches/kdepim/enterprise4/kdepimlibs/qgpgme/dataprovider.cpp #1041823:1041824
@@ -159,9 +159,17 @@
     };
 }
 
+static qint64 blocking_read( const boost::shared_ptr<QIODevice> & io, char * buffer, \
qint64 maxSize ) { +    while ( !io->bytesAvailable() )
+        if ( !io->waitForReadyRead( -1 ) )
+            return 0; // assume EOF (loses error cases :/ )
+
+    return io->read( buffer, maxSize );
+}
+
 ssize_t QIODeviceDataProvider::read( void * buffer, size_t bufSize ) {
 #ifndef NDEBUG
-  //qDebug( "QIODeviceDataProvider::read( %p, %d )", buffer, bufSize );
+  //qDebug( "QIODeviceDataProvider::read( %p, %lu )", buffer, bufSize );
 #endif
   if ( bufSize == 0 )
     return 0;
@@ -172,7 +180,7 @@
   //workaround: some QIODevices (known example: QProcess) might not return 0 (EOF), \
but immediately -1 when finished. If no  //errno is set, gpgme doesn't detect the \
error and loops forever. So return 0 on the very first -1 in case errno is 0  
-  const qint64 numRead = mIO->read( static_cast<char*>(buffer), bufSize );
+  const qint64 numRead = blocking_read( mIO, static_cast<char*>(buffer), bufSize );
 
   Enabler en( numRead < 0 ? &mErrorOccurred : 0 );
   if ( numRead < 0 && errno == 0 ) {


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic