Chapter Contents

Previous

Next
getdtablesize

getdtablesize



Gets Descriptor Table Size

Portability: UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


SYNOPSIS

#include <sys/param.h>
int getdtablesize (void);


DESCRIPTION

getdtablesize returns the maximum number of HFS files and sockets that may be opened. In a system without UNIX System Services (USS), getdtablesize returns the maximum file descriptor number that can be returned for a socket.


RETURN VALUE

getdtablesize returns the maximum number of open HFS files and sockets if it is successful, and it returns a -1 if it is not successful.


EXAMPLE

This example uses getdtablesize to determine the maximum number of sockets that can be opened and allocates storage for file descriptor sets large enough to accomodate this maximum. The file descriptor sets can be later passed to select.

Note that when file descriptor sets are allocated in this fashion, the FD_ZERO macro in <sys/types.h> should not be used as it assumes a fixed size for these sets.

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>

main() 
{
   int maxsockets;
   fd_set *readset, *writeset, *exceptset);
   int ready;

      /* get maximum number of sockets                                */
   maxsockets = getdtablesize();   
   readset = calloc(1, (maxsockets+7)/8);
   writeset = calloc(1, (maxsockets+7)/8);
   exceptset = calloc(1, (maxsockets+7)/8);
                                    
      /* allocate storage for fd sets (8 bits per byte)               */
   .
   .
   .
   ready = select(maxsockets, readset, writeset, exceptset, NULL);
                                    
      /* wait for socket activity                                     */
   .
   .
   .
}


RELATED FUNCTIONS

sysconf


SEE ALSO

Chapter 3, "I/O Functions," in SAS/C Library Reference, Volume 1.
Chapter 2, "Function Categories," in SAS/C Library Reference, Volume 1.


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.