Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
select(2)		      System Calls Manual		     select(2)

NAME
       select -	synchronous I/O	multiplexing

SYNOPSIS
DESCRIPTION
       The  function  indicates	 which of the specified	 file  descriptors  is
       ready for reading, ready	for writing, or	has an error  condition	 pend-
       ing.  If	the specified condition	is false for all of the	specified file
       descriptors, blocks, up to the specified	timeout	 interval,  until  the
       specified condition is true for at least	one  of	the specified file de-
       scriptors.

       The function supports regular files, terminal and  pseudo-terminal  de-
       vices,  STREAMS-based  files, FIFOs and pipes. The behaviour of on file
       descriptors that	refer to other types of	file is	unspecified.

       The nfds	argument specifies the range of	file descriptors to be tested.
       The function tests file descriptors in the range	of 0 to	nfds -1.

       If  the	readfds	argument is not	a null pointer,	it points to an	object
       of type fd_set that on input  specifies	the  file  descriptors	to  be
       checked	for  being  ready  to read, and	on output indicates which file
       descriptors are ready to	read.

       If the writefds argument	is not a null pointer, it points to an	object
       of  type	 fd_set	 that  on  input  specifies the	file descriptors to be
       checked for being  ready	to write, and on output	indicates  which  file
       descriptors are ready to	write.

       If  the errorfds	argument is not	a null pointer,	it points to an	object
       of type fd_setthatoninput specifies the file descriptors	to be  checked
       for  error  conditions pending, and on output indicates which file  de-
       scriptors have error conditions pending.

       On successful completion,  the  objects	pointed	 to  by	 the  readfds,
       writefds,  and  errorfds	 arguments are modified	to indicate which file
       descriptors are ready for reading, ready	for writing, or	have an	 error
       condition  pending,  respectively.  For	each file descriptor less than
       nfds, the corresponding bit will	be set on successful completion	if  it
       was set on input	and the	associated condition is	true for that file de-
       scriptor.

       If the timeout argument is not a	null pointer, it points	to  an	object
       of type structtimeval that specifies a maximum interval to wait for the
       selection to complete. If the timeout argument points to	an  object  of
       type  structtimeval whose members are 0,	does not block.	If the timeout
       argument	is a null pointer, blocks until	an event  causes  one  of  the
       masks  to  be returned with a valid (non-zero) value. If	the time limit
       expires before any event	occurs that would cause	one of the masks to be
       set to a	non-zero value,	completes successfully and returns 0.

       Implementations	may  place limitations on the maximum timeout interval
       supported. On all implementations, the maximum  timeout	interval  sup-
       ported  will  be	 at least 31 days. If the timeout argument specifies a
       timeout interval	greater	than  the  implementation-  dependent  maximum
       value,  the maximum value will be used as the actual timeout value. Im-
       plementations may also place limitations	on the granularity of  timeout
       intervals. If the requested timeout interval requires a finer granular-
       ity than	the implementation supports, the actual	timeout	interval  will
       be rounded up to	the next supported value.

       If  the readfds,	writefds, and errorfds arguments are all null pointers
       and the timeout argument	is not a null pointer,	blocks	for  the  time
       specified, or until interrupted by a signal.  If	the readfds, writefds,
       and errorfds arguments are all null pointers and	the  timeout  argument
       is a null pointer, blocks until interrupted by a	signal.

       File  descriptors  associated with regular files	always select true for
       ready to	read, ready to write, and error	conditions.

       On failure, the objects pointed to by the readfds,  writefds,  and  er-
       rorfds  arguments  are  not  modified.  If the timeout interval expires
       without the specified condition being true for  any  of	the  specified
       file  descriptors, the objects pointed to by the	readfds, writefds, and
       errorfds	arguments have all bits	set to 0.

       File descriptor masks of	type fd_set can	be initialized and tested with
       and  It	is unspecified whether each of these is	a macro	or a function.
       If a macro definition is	suppressed in order to access an actual	 func-
       tion,  or  a  program  defines an external identifier with any of these
       names, the behaviour is undefined.

	      Clears the bit for the file descriptor
					    fd in the file descriptor set  fd-
					    set.

	      Returns a	non-zero value if the bit for the file descriptor
					    fd	is  set	in the file descriptor
					    set	pointed	to  by	fdset,	and  0
					    otherwise.

	      Sets the bit for the file	descriptor
					    fd	in the file descriptor set fd-
					    set.

	      Initializes the file descriptor set
					    fdset to have zero	bits  for  all
					    file descriptors. The behaviour of
					    these macros is undefined  if  the
					    fd	argument  is  less  than  0 or
					    greater than or equal to

RETURN VALUE
       and return  no  value.  returns a non-zero value	if  the	 bit  for  the
       file  descriptor	fd is set in the file descriptor set pointed to	by fd-
       set, and	0 otherwise.

       On successful completion, returns the total number of bits set  in  the
       bit masks. Otherwise, -1	is returned, and is set	to indicate the	error.

ERRORS
       Under the following conditions, fails and sets to:

	      [EBADF]	     One or more of the	file descriptor	sets specified
			     a file descriptor that is not a valid  open  file
			     descriptor.  This could happen either if the file
			     descriptor	sets are not initialized or nfds argu-
			     ment is greater than

	      [EINTR]	     The  function  was	interrupted  before any	of the
			     selected events occurred and before  the  timeout
			     interval  expired.	If has been set	for the	inter-
			     rupting signal,  it  is  implementation-dependent
			     whether restarts or returns with

	      [EINVAL]	     An	 invalid timeout interval was specified. Valid
			     values for	number of  microseconds	 should	 be  a
			     non-negative integer less than 1,000,000 and, for
			     number of seconds,	should be a non-negative inte-
			     ger.

	      [EINVAL]	     The  nfds	argument is less than 0, or is greater
			     than or equal to the value	of which specifies the
			     absolute  maximum	number	of files a process can
			     have open at one time.  If	the resource limit for
			     a	process	is less	than or	equal to 2048, is con-
			     sidered to	be 2048.

	      [EINVAL]	     One of the	specified file descriptors refers to a
			     STREAM or multiplexer that	is linked (directly or
			     indirectly) downstream from a multiplexer.

APPLICATION USAGE
       The use of a timeout does not affect any	pending	timers set up by or

       On successful completion, the object pointed to by the timeout argument
       may be modified.

       The  is	used  in the definition	of structure.  It is set to a value of
       2048 to accommodate 2048	file descriptors.  Any user code that uses  or
       the structure should redefine to	a smaller value	(greater than or equal
       to the number of	open files the process will have)  in  order  to  save
       space.  Similarly, any user code	that wants to test more	than 2048 file
       descriptors should redefine to the required higher value.

       The user	can also allocate the space for	structure dynamically, depend-
       ing  upon  the  number  of file descriptors to be tested. The following
       code segment illustrates	the basic concepts.

SEE ALSO
       fcntl(2), poll(2), read(2), write(2), <sys/time.h>.

CHANGE HISTORY
       First released in Issue 4, Version 2.

select(2)		      System Calls Manual		     select(2)

				  HP-UX	EXTENSIONS

SYNOPSIS
DESCRIPTION
       This function prototype is provided for	backward  compatibility	 only.
       For  this prototype to be used, <time.h>, instead of <sys/time.h>, must
       be included and the symbol _XOPEN_SOURCE_EXTENDED must not  be  defined
       in  the compilation time.  Otherwise, the X/Open	compliant version will
       be used.

       examines	the files or devices  associated  with	the  file  descriptors
       specified  by the bit masks readfds, writefds, and exceptfds.  The bits
       from 0 through nfds-1 are examined.  File descriptor f  is  represented
       by the bit 1<<f in the masks.  More formally, a file descriptor is rep-
       resented	by:

	      fds[(f / BITS_PER_INT)] &	(1 << (f % BITS_PER_INT))

       Ttys and	sockets	are ready for reading or writing, respectively,	 if  a
       or would	not block for one or more of the following reasons:

	      o	 input data is available.

	      o	 output	data can be accepted.

	      o	 an error condition exists, such as a broken pipe, no carrier,
		 or a lost connection.

       TCP sockets select true on reads	only for normal	data.  They do not se-
       lect true on reads if out-of-band data ("urgent"	data) arrives.

       TCP sockets select true on exceptions for out-of-band data.

       AF_CCITT	 sockets  select true on reads for normal and out-of-band data
       and information,	including supervisory frames.

       Pipes are ready for reading if there is any data	in  the	 pipe,	or  if
       there are no writers left for the pipe.	Pipes are ready	for writing if
       there is	room for more data in the pipe AND there are one or more read-
       ers  for	 the pipe, OR there are	no readers left	for the	pipe.  returns
       the same	results	for a pipe whether a file descriptor  associated  with
       the read-only end or the	write-only end of the pipe is used, since both
       file descriptors	refer to the same underlying pipe.  So a  of  a	 read-
       only file descriptor that is associated with a pipe can return ready to
       write, even though that particular file descriptor  cannot  be  written
       to.

ERRORS
	      [EFAULT]	     One or more of the	pointers was invalid.  The re-
			     liable detection of this error is	implementation
			     dependent.

EXAMPLES
       The  following call to checks if	any of 4 terminals are ready for read-
       ing.  times out after 5 seconds if no terminals are ready for  reading.
       Note that the code for opening the terminals or reading from the	termi-
       nals is not shown in this example.  Also, note that this	 example  must
       be  modified  if	 the calling process has more than 32 file descriptors
       open.  Following	this first example is an example of select  with  more
       than 32 file descriptors.

       The  following example is the same as the previous example, except that
       it works	for more than 32 open files.  Definitions for and are in

WARNINGS
       Check all references to signal(5) for appropriateness on	 systems  that
       support can affect the behavior described on this manpage.

       The  file  descriptor  masks are	always modified	on return, even	if the
       call returns as the result of a timeout.

DEPENDENCIES
       supports	the following devices and file types:

	      o	 pipes
	      o	 fifo special files (named pipes)
	      o	 all serial devices
	      o	 All ITEs (internal terminal emulators)	and HP-HIL  input  de-
		 vices
	      o	 lan(7)	special	files
	      o	 pty(7)	special	files
	      o	 sockets

AUTHOR
       was developed by	HP and the University of California, Berkeley.

SEE ALSO
       fcntl(2), read(2), write(2), thread_safety(5).

								     select(2)

NAME | SYNOPSIS | DESCRIPTION | RETURN VALUE | ERRORS | APPLICATION USAGE | SEE ALSO | CHANGE HISTORY | SYNOPSIS | DESCRIPTION | ERRORS | EXAMPLES | WARNINGS | DEPENDENCIES | AUTHOR | SEE ALSO

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=select&sektion=2&manpath=HP-UX+11.22>

home | help