Jump to content

DosSetMaxFH: Difference between revisions

From EDM2
Ak120 (talk | contribs)
m Ak120 moved page OS2 API:CPI:DosSetMaxFH to DosSetMaxFH
Ak120 (talk | contribs)
mNo edit summary
 
Line 1: Line 1:
==Description==
Defines the maximum number of file handles for the calling process.
Defines the maximum number of file handles for the calling process.


==Syntax==
==Syntax==
<PRE>
  DosSetMaxFH(cFH)
#define INCL_DOSFILEMGR
#include <os2.h>
 
ULONG    cFH;  /* Total number of file handles to be provided. */
APIRET    ulrc; /* Return Code. */
 
ulrc = DosSetMaxFH(cFH);
</PRE>


==Parameters==
==Parameters==
Line 17: Line 8:


==Return Code==
==Return Code==
;ulrc (APIRET) - returns
;ulrc (APIRET) - returns:DosSetMaxFH returns one of the following values:
DosSetMaxFH returns one of the following values:
*0 NO_ERROR
* 0   NO_ERROR
*8 ERROR_NOT_ENOUGH_MEMORY
* 8   ERROR_NOT_ENOUGH_MEMORY
*87 ERROR_INVALID_PARAMETER
* 87   ERROR_INVALID_PARAMETER


==Remarks==
==Remarks==
Line 39: Line 29:


int main(VOID){
int main(VOID){
   ULONG    CurMaxFH      = 0;          /* Current count of handles        */
   ULONG    CurMaxFH      = 0;          /* Current count of handles        */
   LONG    ReqCount      = 0;          /* Number to adjust file handles    */
   LONG    ReqCount      = 0;          /* Number to adjust file handles    */
Line 62: Line 51:


   ReqCount = -5L;                    /* Want 5 less file handles        */
   ReqCount = -5L;                    /* Want 5 less file handles        */
   rc = DosSetRelMaxFH(&ReqCount,&CurMaxFH);    /* Change handle maximum */
   rc = DosSetRelMaxFH(&ReqCount,&CurMaxFH);    /* Change handle maximum */


Line 71: Line 59:
     printf("Maximum number of file handles is now %u.\n", CurMaxFH);
     printf("Maximum number of file handles is now %u.\n", CurMaxFH);
   }
   }
   return NO_ERROR;
   return NO_ERROR;
}
}

Latest revision as of 02:30, 21 February 2020

Defines the maximum number of file handles for the calling process.

Syntax

DosSetMaxFH(cFH)

Parameters

cFH (ULONG) - input
Total number of file handles to be provided.

Return Code

ulrc (APIRET) - returns
DosSetMaxFH returns one of the following values:
  • 0 NO_ERROR
  • 8 ERROR_NOT_ENOUGH_MEMORY
  • 87 ERROR_INVALID_PARAMETER

Remarks

OS/2 initially allocates 50 file handles to a process. This is the recommended number for an application. However, if the system limit has not been reached, this amount can be increased with DosSetMaxFH. When DosSetMaxFH is issued, all open file handles are preserved.

If an application tries to set the number of file handles using DosSetMaxFH to a value less than the number of file handles set by OS/2 or a parent process it will return an error return code of 87, ERROR_INVALID_PARAMETER. If a higher limit is set, it can be lowered, but not lower than the value inherited from the system or the parent process.

Applications should instead use DosSetRelMaxFH, to query first and then to set, the maximum number of file handles for a process.

Example Code

This example defines and adjust the maximum number of file handles.

#define INCL_DOSFILEMGR      /* File Manager values */
#define INCL_DOSERRORS       /* DOS Error values */
#include <os2.h>
#include <stdio.h>

int main(VOID){
  ULONG    CurMaxFH      = 0;          /* Current count of handles         */
  LONG     ReqCount      = 0;          /* Number to adjust file handles    */
  APIRET   rc            = NO_ERROR;   /* Return code                      */

  rc = DosSetRelMaxFH(&ReqCount,     /* Using 0 here will return the       */
                      &CurMaxFH);    /* current number of file handles     */

  if (rc != NO_ERROR) {
     printf("DosSetRelMaxFH error: return code = %u\n", rc);
     return 1;
  } else {
     printf("Maximum number of file handles is %u.\n", CurMaxFH);
  }

  rc = DosSetMaxFH(110L);            /* Set maximum file handles to 110  */

  if (rc != NO_ERROR) {
     printf("DosSetMaxFH error: return code = %u\n", rc);
     return 1;
  }

  ReqCount = -5L;                    /* Want 5 less file handles         */
  rc = DosSetRelMaxFH(&ReqCount,&CurMaxFH);     /* Change handle maximum */

  if (rc != NO_ERROR) {
     printf("DosSetRelMaxFH error: return code = %u\n", rc);
     return 1;
  } else {
     printf("Maximum number of file handles is now %u.\n", CurMaxFH);
  }
  return NO_ERROR;
}

Related Functions