OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [tcpip/] [current/] [doc/] [select.html] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
<html>
2
<body>
3
<pre>
4
NAME
5
       select,  FD_CLR,  FD_ISSET,  FD_SET, FD_ZERO - synchronous
6
       I/O multiplexing
7
 
8
SYNOPSIS
9
       #include &lt;network.h&gt;
10
 
11
       int  select(int  n,  fd_set  *readfds,  fd_set  *writefds,
12
       fd_set *exceptfds, struct timeval *timeout);
13
 
14
       FD_CLR(int fd, fd_set *set);
15
       FD_ISSET(int fd, fd_set *set);
16
       FD_SET(int fd, fd_set *set);
17
       FD_ZERO(fd_set *set);
18
 
19
DESCRIPTION
20
       select  waits  for  a number of file descriptors to change
21
       status.
22
 
23
       Three independent sets of descriptors are watched.   Those
24
       listed  in  readfds  will  be watched to see if characters
25
       become available for reading, those in  writefds  will  be
26
       watched  to  see if it is ok to immediately write on them,
27
       and those in exceptfds will be watched for exceptions.  On
28
       exit,  the  sets  are  modified in place to indicate which
29
       descriptors actually changed status.
30
 
31
       Four macros are provided to manipulate the sets.   FD_ZERO
32
       will clear a set.  FD_SET and FD_CLR add or remove a given
33
       descriptor from  a  set.   FD_ISSET  tests  to  see  if  a
34
       descriptor is part of the set; this is useful after select
35
       returns.
36
 
37
       n is the highest-numbered descriptor in any of  the  three
38
       sets, plus 1.
39
 
40
       timeout  is  an  upper bound on the amount of time elapsed
41
       before select returns. It may be zero, causing  select  to
42
       return  immediately.  If  timeout  is  NULL  (no timeout),
43
       select can block indefinitely.
44
 
45
RETURN VALUE
46
       On success, select returns the number of descriptors  con-
47
       tained  in  the  descriptor sets, which may be zero if the
48
       timeout expires before anything interesting  happens.   On
49
       error, -1 is returned, and errno is set appropriately; the
50
       sets and timeout become undefined, so do not rely on their
51
       contents after an error.
52
 
53
ERRORS
54
       EBADF   An invalid file descriptor was given in one of the
55
               sets.
56
 
57
       EINTR   A non blocked signal was caught.
58
 
59
       EINVAL  n is negative.
60
 
61
       ENOMEM  select was unable to allocate memory for  internal
62
               tables.
63
 
64
NOTES
65
       Some  code calls select with all three sets empty, n zero,
66
       and a non-null timeout as a fairly portable way  to  sleep
67
       with subsecond precision.
68
 
69
EXAMPLE
70
       #include <stdio.h>
71
       #include <sys/time.h>
72
       #include <sys/types.h>
73
       #include <unistd.h>
74
 
75
       int
76
       main(void)
77
       {
78
           fd_set rfds;
79
           struct timeval tv;
80
           int retval;
81
 
82
           /* Watch stdin (fd 0) to see when it has input. */
83
           FD_ZERO(&rfds);
84
           FD_SET(0, &rfds);
85
           /* Wait up to five seconds. */
86
           tv.tv_sec = 5;
87
           tv.tv_usec = 0;
88
 
89
           retval = select(1, &rfds, NULL, NULL, &tv);
90
           /* Don't rely on the value of tv now! */
91
 
92
           if (retval)
93
               printf("Data is available now.\n");
94
               /* FD_ISSET(0, &rfds) will be true. */
95
           else
96
               printf("No data within five seconds.\n");
97
 
98
           exit(0);
99
       }
100
 
101
       Generally  portable  to/from  non-BSD  systems  supporting
102
       clones  of  the BSD socket layer (including System V vari-
103
       ants).  However, note that the System V variant  typically
104
       sets the timeout variable before exit, but the BSD variant
105
       does not.
106
</pre>
107
</body>
108
</html>

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.