diff --git a/ChangeLog.txt b/ChangeLog.txt index 376654848e..79cc0d1ed9 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,11 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2014-01-13 12:40 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * src/rtl/hbproces.c + % optimized MS-Windows version of hb_fsProcessRun() when only single + stream is redirected + 2014-01-12 20:28 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/rtl/filesys.c + added support for setting non blocking mode in MS-Windows builds diff --git a/src/rtl/hbproces.c b/src/rtl/hbproces.c index e0ea222a31..b8ab77d42f 100644 --- a/src/rtl/hbproces.c +++ b/src/rtl/hbproces.c @@ -988,6 +988,7 @@ int hb_fsProcessRun( const char * pszFilename, { #if defined( HB_OS_WIN ) HB_BOOL fFinished = HB_FALSE; + int iPipeCount = 0; if( nStdInLen == 0 && hStdin != FS_ERROR ) { @@ -996,11 +997,21 @@ int hb_fsProcessRun( const char * pszFilename, } if( hStdin != FS_ERROR ) - hb_fsPipeUnblock( hStdin ); + ++iPipeCount; if( hStdout != FS_ERROR ) - hb_fsPipeUnblock( hStdout ); + ++iPipeCount; if( hStderr != FS_ERROR ) - hb_fsPipeUnblock( hStderr ); + ++iPipeCount; + + if( iPipeCount > 1 ) + { + if( hStdin != FS_ERROR ) + hb_fsPipeUnblock( hStdin ); + if( hStdout != FS_ERROR ) + hb_fsPipeUnblock( hStdout ); + if( hStderr != FS_ERROR ) + hb_fsPipeUnblock( hStderr ); + } for( ;; ) { @@ -1019,6 +1030,12 @@ int hb_fsProcessRun( const char * pszFilename, nLen = hb_fsReadLarge( hStdout, pOutBuf + nOutBuf, nOutSize - nOutBuf ); if( nLen > 0 ) nOutBuf += nLen; + else if( iPipeCount == 1 ) + { + hb_fsClose( hStdout ); + hStdout = FS_ERROR; + iPipeCount = 0; + } dwWait = nLen > 0 ? 0 : 10; } @@ -1032,6 +1049,12 @@ int hb_fsProcessRun( const char * pszFilename, nLen = hb_fsReadLarge( hStderr, pErrBuf + nErrBuf, nErrSize - nErrBuf ); if( nLen > 0 ) nErrBuf += nLen; + else if( iPipeCount == 1 ) + { + hb_fsClose( hStderr ); + hStderr = FS_ERROR; + iPipeCount = 0; + } if( dwWait ) dwWait = nLen > 0 ? 0 : 10; } @@ -1046,15 +1069,19 @@ int hb_fsProcessRun( const char * pszFilename, nLen = hb_fsWriteLarge( hStdin, pStdInBuf, nStdInLen ); pStdInBuf += nLen; nStdInLen -= nLen; - if( nStdInLen == 0 ) + if( nStdInLen == 0 || ( iPipeCount == 1 && nLen == 0 ) ) { hb_fsClose( hStdin ); hStdin = FS_ERROR; + if( iPipeCount == 1 ) + iPipeCount = 0; } else if( dwWait ) dwWait = nLen > 0 ? 0 : 10; } + if( iPipeCount == 0 ) + dwWait = INFINITE; dwResult = WaitForSingleObject( ( HANDLE ) hb_fsGetOsHandle( hProcess ), dwWait ); if( dwResult == WAIT_OBJECT_0 ) {