![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| fork system call | u_peerless | UNIX for Dummies Questions & Answers | 1 | 06-23-2008 07:25 AM |
| c system call | rangaswamy | High Level Programming | 1 | 02-19-2008 09:53 AM |
| error "Invalid argument" returned after call sched_setscheduler | robin.zhu | High Level Programming | 1 | 07-26-2007 12:51 AM |
| how to differentiate system call from library call | muru | UNIX for Advanced & Expert Users | 2 | 07-19-2007 08:20 PM |
| call execl with int as argument | Dana73 | High Level Programming | 2 | 02-10-2006 01:42 PM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
how to use exceptfds argument in select system call
Hi,
Can any one tell me how to use the fourth argument of select system call.I saw example "port forwarding" on the net,but it was too complex for me to understand.Can any one explain me about the usage of exceptfds argument of select system call with simple example. Thanks. |
| Forum Sponsor | ||
|
|
|
|||
|
Arguments 2, 3, and 4 are all the same thing - an fd_set (which is a datatype defined in sys/select.h. Arg #2 is the fd_set for fd's you have open for reading. #3 is for writing,
#4 is for error streams like stderr. An fd_set is a "list" of file descriptor numbers that select is supposed to check for you. select() clears the values (meaning you have to reset the values in each of the fd_set objects), and on success it sets only those fd values that you can : read(#2) write(#3) errorstream(#4). Use the following macros to set, clear, or test an fd_set FD_ZERO - initialize FD_SET - turn on an fd value setting FD_CLR - turn off an fd value setting in the set FD_ISSET - test to see if a value is on or off. |
|
|||
|
Code:
#define MASK(f) (1 << (f))
#define NTTYS 4
int tty[NTTYS];
int ttymask[NTTYS];
int readmask = 0;
int readfds;
int nfound, i;
struct timeval timeout;
/* First open each terminal for reading and put the
* file descriptors into array tty[NTTYS]. The code
* for opening the terminals is not shown here.
*/
for (i=0; i < NTTYS; i++) {
ttymask[i] = MASK(tty[i]);
readmask |= ttymask[i];
}
timeout.tv_sec = 5;
timeout.tv_usec = 0;
readfds = readmask;
/* select on NTTYS+3 file descriptors if stdin, stdout
* and stderr are also open
*/
if ((nfound = select (NTTYS+3, &readfds, 0, 0, &timeout)) == -1)
perror ("select failed");
else if (nfound == 0)
printf ("select timed out \n");
else for (i=0; i < NTTYS; i++)
if (ttymask[i] & readfds)
/* Read from tty[i]. The code for reading
* is not shown here.
*/
else printf ("tty[%d] is not ready for reading \n",i);
|
|||
| Google UNIX.COM |