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
 
(2 intermediate revisions by the same user not shown)
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==
; 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:
 
*0 NO_ERROR
DosSetMaxFH returns one of the following values:
*8 ERROR_NOT_ENOUGH_MEMORY
 
*87 ERROR_INVALID_PARAMETER
* 0   NO_ERROR  
* 8   ERROR_NOT_ENOUGH_MEMORY  
* 87   ERROR_INVALID_PARAMETER


==Remarks==
==Remarks==
Line 34: Line 22:
==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 42: 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 65: 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 74: 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;
}
}
</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]]

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