The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-08-2008
Registered User
 

Join Date: Jul 2008
Posts: 1
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.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-09-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,494
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.
Reply With Quote
  #3 (permalink)  
Old 07-11-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,494
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);
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:42 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0