Jump to content

DosSetMaxFH: Difference between revisions

From EDM2
Created page with "==Description== Defines the maximum number of file handles for the calling process. ==Syntax== <PRE> #define INCL_DOSFILEMGR #include <os2.h> ULONG cFH; /* Total numb..."
 
Ak120 (talk | contribs)
mNo edit summary
Line 7: Line 7:
#include <os2.h>
#include <os2.h>


ULONG    cFH;  /* Total number of file handles to be provided. */
ULONG    cFH;  /* Total number of file handles to be provided. */
APIRET    ulrc;  /* Return Code. */
APIRET    ulrc;  /* Return Code. */


ulrc = DosSetMaxFH(cFH);
ulrc = DosSetMaxFH(cFH);
</PRE>


</PRE>
==Parameters==
==Parameters==
; cFH (ULONG) - input : Total number of file handles to be provided.
;cFH (ULONG) - input : Total number of file handles to be provided.


==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


Line 34: Line 32:
==Example Code==
==Example Code==
This example defines and adjust the maximum number of file handles.
This example defines and adjust the maximum number of file handles.
<PRE>
<PRE>
#define INCL_DOSFILEMGR      /* File Manager values */
#define INCL_DOSFILEMGR      /* File Manager values */
Line 77: Line 74:
   return NO_ERROR;
   return NO_ERROR;
}
}
</PRE>


</PRE>
==Related Functions==
==Related Functions==
* [[OS2 API:CPI:DosDupHandle|DosDupHandle]]
* [[DosDupHandle]]
* [[OS2 API:CPI:DosOpen|DosOpen]]
* [[DosOpen]]
* [[OS2 API:CPI:DosSetRelMaxFH|DosSetRelMaxFH]]  
* [[DosSetRelMaxFH]]
 


[[Category:The OS/2 API Project]]
[[Category:Dos]]

Revision as of 00:03, 2 December 2016

Description

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

Syntax

#define INCL_DOSFILEMGR
#include <os2.h>

ULONG     cFH;   /* Total number of file handles to be provided. */
APIRET    ulrc;  /* Return Code. */

ulrc = 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