From 682d8e32e3368d4f5d7a1b4af2f94c300b18bef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Fri, 15 Jan 2016 16:02:45 +0100 Subject: [PATCH] 2016-01-15 16:02 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * include/hbapifs.h * src/common/hbfsapi.c + added automatic file handle table resizing to hb_fsOS2DosOpenL() + added new C function: hb_fsOS2DosOpen() which is wrapper to DosOpen() with automatic file handle table resizing. Please remember that unlike hb_fsOS2DosOpenL() this function is pure wrapper to DosOpen() so it does not make file name conversions and does not set hb_fsError(). * src/rtl/filesys.c * src/rtl/hbcom.c * src/rtl/hbproces.c * use hb_fsOS2DosOpen() instead of DosOpen() * src/vm/cmdarg.c * set the initial size of file handle table to 256 in OS2 OpenWatcom builds if user does not set it explicitly by //F: switch * config/global.mk - removed set HARBOUR=F:100 - it's not necessary with automatic FHT resizing ; Please test it in real OS2 environment --- ChangeLog.txt | 25 ++++++++++++++ config/global.mk | 5 --- include/hbapifs.h | 4 +++ src/common/hbfsapi.c | 77 +++++++++++++++++++++++++++++++++++++------- src/rtl/filesys.c | 14 +++++--- src/rtl/hbcom.c | 20 +++++++----- src/rtl/hbproces.c | 12 +++++-- src/vm/cmdarg.c | 8 +++++ 8 files changed, 132 insertions(+), 33 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 4d0164e5b4..97d6b4e932 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,31 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2016-01-15 16:02 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * include/hbapifs.h + * src/common/hbfsapi.c + + added automatic file handle table resizing to hb_fsOS2DosOpenL() + + added new C function: hb_fsOS2DosOpen() which is wrapper to DosOpen() + with automatic file handle table resizing. + Please remember that unlike hb_fsOS2DosOpenL() this function is + pure wrapper to DosOpen() so it does not make file name conversions + and does not set hb_fsError(). + + * src/rtl/filesys.c + * src/rtl/hbcom.c + * src/rtl/hbproces.c + * use hb_fsOS2DosOpen() instead of DosOpen() + + * src/vm/cmdarg.c + * set the initial size of file handle table to 256 in OS2 OpenWatcom + builds if user does not set it explicitly by //F: switch + + * config/global.mk + - removed set HARBOUR=F:100 - it's not necessary with automatic FHT + resizing + + ; Please test it in real OS2 environment + 2016-01-15 15:20 UTC+0100 Viktor Szakats (vszakats users.noreply.github.com) * * % remove brandings and homepage from copyright header. Pass 3 - manual. diff --git a/config/global.mk b/config/global.mk index b68c784dcb..2bdd731f29 100644 --- a/config/global.mk +++ b/config/global.mk @@ -2042,11 +2042,6 @@ export HARBOURCMD := export CLIPPER := export CLIPPERCMD := -# in OS2 increase maximum number of file handle from 20 to 100 for -j build switch -ifeq ($(HB_HOST_PLAT),os2) - export HARBOUR := F:100 -endif - # relevant only on non-*nix hosts where --print-directory is on by default ifeq ($(findstring w,$(MAKEFLAGS)),) MKFLAGS := --no-print-directory diff --git a/include/hbapifs.h b/include/hbapifs.h index ab45614c26..9fb4fbbdec 100644 --- a/include/hbapifs.h +++ b/include/hbapifs.h @@ -301,6 +301,10 @@ extern HB_EXPORT HB_WCHAR * hb_fsNameConvU16( const char * pszFileName ); #endif #if defined( HB_OS_OS2 ) extern HB_EXPORT HB_BOOL hb_isWSeB( void ); +extern HB_EXPORT HB_ULONG hb_fsOS2DosOpen( const char * pszFileName, + HB_FHANDLE * pHFile, HB_ULONG * pulAction, + HB_ULONG nInitSize, HB_ULONG ulAttribute, + HB_ULONG fsOpenFlags, HB_ULONG fsOpenMode ); extern HB_EXPORT HB_ULONG hb_fsOS2DosOpenL( const char * pszFileName, HB_FHANDLE * pHFile, HB_ULONG * pulAction, HB_FOFFSET nInitSize, HB_ULONG ulAttribute, diff --git a/src/common/hbfsapi.c b/src/common/hbfsapi.c index f063ef159c..054c0510fd 100644 --- a/src/common/hbfsapi.c +++ b/src/common/hbfsapi.c @@ -351,29 +351,82 @@ HB_BOOL hb_isWSeB( void ) return s_iWSeB; } +HB_ULONG hb_fsOS2DosOpen( const char * pszFileName, + HB_FHANDLE * pHFile, HB_ULONG * pulAction, + HB_ULONG nInitSize, HB_ULONG ulAttribute, + HB_ULONG fsOpenFlags, HB_ULONG fsOpenMode ) +{ + ULONG cbMaxFH = 20; + HFILE hFile = ( HFILE ) -1; + APIRET ret; + + for( ;; ) + { + ret = DosOpen( ( PSZ ) pszFileName, &hFile, pulAction, nInitSize, + ulAttribute, fsOpenFlags, fsOpenMode, NULL ); + if( ret == ERROR_TOO_MANY_OPEN_FILES ) + { + LONG cbReqCount = 64; + ULONG cbCurMaxFH = 0; + ret = DosSetRelMaxFH( &cbReqCount, &cbCurMaxFH ); + if( ret == NO_ERROR && cbCurMaxFH > cbMaxFH ) + { + cbMaxFH = cbCurMaxFH; + continue; + } + ret = ERROR_TOO_MANY_OPEN_FILES; + } + break; + } + /* Hack to make error reporting more DOS compatible, anyhow I'm + not sure it's good idea to have it [druzus] */ + if( ret == ERROR_OPEN_FAILED ) + ret = ERROR_FILE_NOT_FOUND; + + *pHFile = ret == NO_ERROR ? ( HB_FHANDLE ) hFile : FS_ERROR; + + return ret; +} + HB_ULONG hb_fsOS2DosOpenL( const char * pszFileName, HB_FHANDLE * pHFile, HB_ULONG * pulAction, HB_FOFFSET nInitSize, HB_ULONG ulAttribute, HB_ULONG fsOpenFlags, HB_ULONG fsOpenMode ) { + ULONG cbMaxFH = 20; char * pszFree; HFILE hFile = ( HFILE ) -1; APIRET ret; pszFileName = hb_fsNameConv( pszFileName, &pszFree ); - if( hb_isWSeB() ) - /* if other process open file using DosOpen() then it will block - long file support for us, we can block other processes against - using DosOpen() by setting OPEN_SHARE_DENYLEGACY in fsOpenMode. - Is it good idea? [druzus] */ - ret = s_DosOpenL( ( PSZ ) pszFileName, &hFile, pulAction, - ( LONGLONG ) nInitSize, ulAttribute, + for( ;; ) + { + if( hb_isWSeB() ) + /* if other process open file using DosOpen() then it will block + long file support for us, we can block other processes against + using DosOpen() by setting OPEN_SHARE_DENYLEGACY in fsOpenMode. + Is it good idea? [druzus] */ + ret = s_DosOpenL( ( PSZ ) pszFileName, &hFile, pulAction, + ( LONGLONG ) nInitSize, ulAttribute, + fsOpenFlags, fsOpenMode, NULL ); + else + ret = DosOpen( ( PSZ ) pszFileName, &hFile, pulAction, + ( ULONG ) nInitSize, ulAttribute, fsOpenFlags, fsOpenMode, NULL ); - else - ret = DosOpen( ( PSZ ) pszFileName, &hFile, pulAction, - ( ULONG ) nInitSize, ulAttribute, - fsOpenFlags, fsOpenMode, NULL ); - + if( ret == ERROR_TOO_MANY_OPEN_FILES ) + { + LONG cbReqCount = 64; + ULONG cbCurMaxFH = 0; + ret = DosSetRelMaxFH( &cbReqCount, &cbCurMaxFH ); + if( ret == NO_ERROR && cbCurMaxFH > cbMaxFH ) + { + cbMaxFH = cbCurMaxFH; + continue; + } + ret = ERROR_TOO_MANY_OPEN_FILES; + } + break; + } /* Hack to make error reporting more DOS compatible, anyhow I'm not sure it's good idea to have it [druzus] */ if( ret == ERROR_OPEN_FAILED ) diff --git a/src/rtl/filesys.c b/src/rtl/filesys.c index af254d93ff..0bfd4c327e 100644 --- a/src/rtl/filesys.c +++ b/src/rtl/filesys.c @@ -914,13 +914,17 @@ HB_BOOL hb_fsPipeCreate( HB_FHANDLE hPipe[ 2 ] ) { /* open the write end of then named pipe */ ULONG ulAction = 0; - ret = DosOpen( ( PSZ ) szPipeName, &hPipeWr, &ulAction, 0, - FILE_NORMAL, - OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS, - OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYNONE | OPEN_FLAGS_FAIL_ON_ERROR, - NULL ); + HB_FHANDLE hFile; + + ret = hb_fsOS2DosOpen( szPipeName, &hFile, &ulAction, 0, + FILE_NORMAL, + OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS, + OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYNONE | OPEN_FLAGS_FAIL_ON_ERROR ); if( ret == NO_ERROR ) + { + hPipeWr = ( HFILE ) hFile; break; + } } DosClose( hPipeRd ); } diff --git a/src/rtl/hbcom.c b/src/rtl/hbcom.c index 6e6db86b30..72641a6577 100644 --- a/src/rtl/hbcom.c +++ b/src/rtl/hbcom.c @@ -3060,19 +3060,23 @@ int hb_comOpen( int iPort ) char buffer[ HB_COM_DEV_NAME_MAX ]; const char * pszName = hb_comGetName( pCom, buffer, sizeof( buffer ) ); ULONG ulAction = 0; + HB_FHANDLE hFile; + hb_vmUnlock(); - rc = DosOpen( ( PSZ ) pszName, - &pCom->hFile, - &ulAction, - 0L, - FILE_NORMAL, - OPEN_ACTION_OPEN_IF_EXISTS, - OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYREADWRITE, - 0L ); + rc = hb_fsOS2DosOpen( pszName, + &hFile, + &ulAction, + 0L, + FILE_NORMAL, + OPEN_ACTION_OPEN_IF_EXISTS, + OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYREADWRITE ); if( rc == NO_ERROR ) + { + pCom->hFile = ( HFILE ) hFile; pCom->status |= HB_COM_OPEN; + } hb_comSetOsError( pCom, rc ); diff --git a/src/rtl/hbproces.c b/src/rtl/hbproces.c index 2e54552329..a508e721bd 100644 --- a/src/rtl/hbproces.c +++ b/src/rtl/hbproces.c @@ -580,9 +580,15 @@ HB_FHANDLE hb_fsProcessOpen( const char * pszFileName, PHB_GT pGT; if( fDetach && ( ! phStdin || ! phStdout || ! phStderr ) ) - ret = DosOpen( ( PCSZ ) "NUL:", &hNull, &ulState, 0, - FILE_NORMAL, OPEN_ACCESS_READWRITE, - OPEN_ACTION_OPEN_IF_EXISTS, NULL ); + { + HB_FHANDLE hFile; + + ret = hb_fsOS2DosOpen( "NUL:", &hFile, &ulState, 0, + FILE_NORMAL, OPEN_ACCESS_READWRITE, + OPEN_ACTION_OPEN_IF_EXISTS ); + if( ret == NO_ERROR ) + hNull = ( HFILE ) hFile; + } if( ret == NO_ERROR && phStdin != NULL ) { diff --git a/src/vm/cmdarg.c b/src/vm/cmdarg.c index edab950f3d..23c83783b3 100644 --- a/src/vm/cmdarg.c +++ b/src/vm/cmdarg.c @@ -862,6 +862,14 @@ void hb_cmdargProcess( void ) #endif #endif } + else if( iHandles < 0 ) + { + #if defined( __WATCOMC__ ) + #if defined( HB_OS_OS2 ) + DosSetMaxFH( 256 ); + #endif + #endif + } } /* Source repository revision number */