From c8deb0385a4aa07e4fad7518e1a88be480a28619 Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Fri, 5 Oct 2007 00:20:43 +0000 Subject: [PATCH] 2007-10-05 Marcus Brinkmann * kdpipeiodevice.cpp, w32-qt-io.cpp: New versions from Frank Osterfeld. --- gpgme/ChangeLog | 5 +++++ gpgme/kdpipeiodevice.cpp | 3 ++- gpgme/w32-qt-io.cpp | 19 +++++++++++++++---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index 77de5ea..91c202c 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,3 +1,8 @@ +2007-10-05 Marcus Brinkmann + + * kdpipeiodevice.cpp, w32-qt-io.cpp: New versions from Frank + Osterfeld. + 2007-10-04 Marcus Brinkmann * kdpipeiodevice.h, kdpipeiodevice.cpp, kdpipeiodevice.moc, diff --git a/gpgme/kdpipeiodevice.cpp b/gpgme/kdpipeiodevice.cpp index 1fd0ef0..3e206c3 100644 --- a/gpgme/kdpipeiodevice.cpp +++ b/gpgme/kdpipeiodevice.cpp @@ -493,7 +493,7 @@ bool KDPipeIODevice::writeWouldBlock() const { d->startWriterThread(); LOCKED( d->writer ); - return d->writer->bufferFull() && !d->writer->error; + return !d->writer->bufferEmpty() && !d->writer->error; } @@ -684,6 +684,7 @@ void Reader::run() { if ( !cancel && ( eof || error ) ) { qDebug( "%p: Reader::run: received eof(%d) or error(%d), waking everyone", this, eof, error ); notifyReadyRead(); + cancel = true; } else if ( !cancel && !bufferFull() && !bufferEmpty() ) { qDebug( "%p: Reader::run: buffer no longer empty, waking everyone", this ); notifyReadyRead(); diff --git a/gpgme/w32-qt-io.cpp b/gpgme/w32-qt-io.cpp index dd17e87..ba43913 100644 --- a/gpgme/w32-qt-io.cpp +++ b/gpgme/w32-qt-io.cpp @@ -85,8 +85,9 @@ using _gpgme_::KDPipeIODevice; #define MAX_SLAFD 1024 struct DeviceEntry { - DeviceEntry() : iodev( 0 ), refCount( 1 ) {} + DeviceEntry() : iodev( 0 ), refCount( 1 ), blocking( true ) {} KDPipeIODevice* iodev; + bool blocking; mutable int refCount; void ref() const { ++refCount; } int unref() const { assert( refCount > 0 ); return --refCount; } @@ -152,7 +153,11 @@ _gpgme_io_read (int fd, void *buffer, size_t count) return TRACE_SYSRES (-1); } TRACE_LOG1 ("channel %p", chan); - + if ( iodevice_table[fd] && !iodevice_table[fd]->blocking && chan->readWouldBlock() ) { + errno = EAGAIN; + return TRACE_SYSRES( -1 ); + } + nread = chan->read ((char *) buffer, count); if (nread < 0) { @@ -185,6 +190,11 @@ _gpgme_io_write (int fd, const void *buffer, size_t count) return -1; } + if ( iodevice_table[fd] && !iodevice_table[fd]->blocking && chan->writeWouldBlock() ) + { + errno = EAGAIN; + return TRACE_SYSRES( -1 ); + } nwritten = chan->write ((char *) buffer, count); if (nwritten < 0) @@ -323,8 +333,9 @@ _gpgme_io_set_close_notify (int fd, _gpgme_close_notify_handler_t handler, int _gpgme_io_set_nonblocking (int fd) { - /* Qt always uses non-blocking IO, except for files, maybe, but who - uses that? */ + DeviceEntry* const entry = iodevice_table[fd]; + assert( entry ); + entry->blocking = false; TRACE_BEG (DEBUG_SYSIO, "_gpgme_io_set_nonblocking", fd); return TRACE_SYSRES (0); } -- 2.26.2