how to use exceptfds argument in select system call


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users how to use exceptfds argument in select system call
# 1  
Old 07-09-2008
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.
# 2  
Old 07-09-2008
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.
# 3  
Old 07-11-2008
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);

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Conditionally replace nth argument of every function call

I have very large perl source code file and I want to replace every occurrence function say foo,The function foo has some arguments and I want to replace 2nd argument,the current argument is hex integer and i want to replace it to equivalent string.Also I want to replace function name foo with... (4 Replies)
Discussion started by: pravint
4 Replies

2. UNIX for Advanced & Expert Users

Issues with select system call

1. We are using client-server model communication using TCP/IP protocol 2. The TCP socket created with O_NON_BLOCK flag 3. When we make attempt to send large data to other process, the send is partially successful. It means we attempt to send 90K data, OS sent only 40K data successfully. ... (3 Replies)
Discussion started by: MasthanDudekula
3 Replies

3. Homework & Coursework Questions

program to send messages to parent using pipes and select system call

Write a program using select, which will create some number of child processes that continuously send text messages to the parent process using pipes. Each child has its own pipe that it uses to communicate with the parent. The parent uses select () to decide what pipes should be processed to... (1 Reply)
Discussion started by: ripssingh
1 Replies

4. UNIX for Dummies Questions & Answers

How to select correct partition and kernel argument for grub?

I use command-line mode of GRUB to load kernel, but I can not know how to chose the partition and kernel argument, as followed : please tell me how to do deal with , thanks! (0 Replies)
Discussion started by: cqlouis
0 Replies

5. Programming

select() system call takes longer than the timeout specified

Below is my code. Every once in a while the select call takes as long as 150 seconds (discovered by printing time before and after this statement) while the timeout specified into it is only 1 second. Any clue why? I can't believe that select call which has been around for centuries can have a bug,... (15 Replies)
Discussion started by: old_as_a_fossil
15 Replies

6. Shell Programming and Scripting

Passing argument to system call in awk script

So, I have this script. It reads a CSV file that has a mixture of object names with IP addresses (parsing out that part I have working), and object names which have a DNS name. I want to be able to run a "dig +short" based off of the name given to me in the line of the awk script, and then deal... (6 Replies)
Discussion started by: mikesimone
6 Replies

7. Programming

Having some trouble with select() call in C

I have this while loop: while (notdone) { //Set the timers waitd.tv_sec = 5; waitd.tv_usec = 0; FD_ZERO(&tempreadfds); FD_ZERO(&tempwritefds); FD_ZERO(&readfds); /* initialize the read fd set */ FD_ZERO(&writefds); /* initialize the write fd set */ ... (1 Reply)
Discussion started by: Legend986
1 Replies

8. Shell Programming and Scripting

Function call with argument doubt

Hi all, I am having a problem with user defined function call. I am new into the concept of shell script UDFs. My function is: iterate_directory() { cd $1 k=0 for i in * do if then ARR=${i} fi done echo ${ARR } } (4 Replies)
Discussion started by: canishk
4 Replies

9. Programming

error "Invalid argument" returned after call sched_setscheduler

the code is below and the was run on Solaris 9. ----------------------------- struct sched_param param; param.sched_priority = 99; if(sched_setscheduler(0, SCHED_RR, &param) == -1) { perror("setting priority"); exit(1); } ------------------------------- after the... (1 Reply)
Discussion started by: robin.zhu
1 Replies

10. UNIX for Advanced & Expert Users

how to differentiate system call from library call

Hi, Ho do I differentiate system call from library call? for example if I am using chmod , how do I find out if it is a system call or library call? Thanks Muru (2 Replies)
Discussion started by: muru
2 Replies
Login or Register to Ask a Question