--- qsampler/trunk/src/qsamplerMessages.cpp 2015/10/01 18:22:23 2847 +++ qsampler/trunk/src/qsamplerMessages.cpp 2015/10/03 15:48:18 2848 @@ -1,7 +1,7 @@ // qsamplerMessages.cpp // /**************************************************************************** - Copyright (C) 2004-2014, rncbc aka Rui Nuno Capela. All rights reserved. + Copyright (C) 2004-2015, rncbc aka Rui Nuno Capela. All rights reserved. Copyright (C) 2007, Christian Schoenebeck This program is free software; you can redistribute it and/or @@ -113,15 +113,28 @@ } +// Set stdout/stderr blocking mode. +bool Messages::stdoutBlock ( int fd, bool bBlock ) const +{ +#if !defined(WIN32) + const int iFlags = ::fcntl(fd, F_GETFL, 0); + const bool bNonBlock = bool(iFlags & O_NONBLOCK); + if (bBlock && bNonBlock) + bBlock = (::fcntl(fd, F_SETFL, iFlags & ~O_NONBLOCK) == 0); + else + if (!bBlock && !bNonBlock) + bBlock = (::fcntl(fd, F_SETFL, iFlags | O_NONBLOCK) != 0); +#endif + return bBlock; +} + + // Own stdout/stderr socket notifier slot. void Messages::stdoutNotify ( int fd ) { #if !defined(WIN32) // Set non-blocking reads, if not already... - const int iFlags = ::fcntl(fd, F_GETFL, 0); - int iBlock = ((iFlags & O_NONBLOCK) == 0); - if (iBlock) - iBlock = ::fcntl(fd, F_SETFL, iFlags | O_NONBLOCK); + const bool bBlock = stdoutBlock(fd, false); // Read as much as is available... QString sTemp; char achBuffer[1024]; @@ -130,7 +143,7 @@ while (cchRead > 0) { achBuffer[cchRead] = (char) 0; sTemp.append(achBuffer); - cchRead = (iBlock ? 0 : ::read(fd, achBuffer, cchBuffer)); + cchRead = (bBlock ? 0 : ::read(fd, achBuffer, cchBuffer)); } // Needs to be non-empty... if (!sTemp.isEmpty())