What would I use in place of select()

This is a discussion on What would I use in place of select() within the Linux Programming forums, part of the Platform Specific Boards category; I'm modifying some code so that there is a timer on in. When the system has select(), I can just ...

  1. #1
    Banned
    Join Date
    May 2007
    Location
    Berkeley, CA
    Posts
    329

    What would I use in place of select()

    I'm modifying some code so that there is a timer on in. When the system has select(), I can just place a timer on select. However, what are some alternatives in the noselect case? Here is a code snippet to give you some idea,

    Code:
    /*Here is the section that has a timer*/
    #ifndef NOSELECT
         /* Set up the input file set for the select call */
         FD_ZERO(&input_set);
         FD_SET(0,&input_set);
         FD_SET(rst,&input_set);
         struct timeval tv;
    
         tv.tv_sec = atoi(opt[OPT_IDLEOUT].str)*60;
         tv.tv_usec = 0;
     #endif
    
    
     /*What are some ideas that I could do this case?*/
     #ifdef NOSELECT
             /* Copy text while I can -- otherwise go to input mode */
             if (output())
             { /*}*/
                 /* Wait four seconds for a command */
                 alarm(4);
                 if (!setjump(jenv,1))
                 {
                     read(0,&ch,1);  /* Alarm busts us out of here */
                     alarm(0);
                     docmd(ch);
                     lastaction= time((time_t *)0);
                 }
     #else
    
     /* Wait for input in file or from user */
             iset= input_set;
             select(rst+1, &iset, NULL, NULL, &tv);/* process typed command from user */
            if (FD_ISSET(0,&iset))
            {
                read(0,&ch,1);
                docmd(ch);
                lastaction= time((time_t *)0);
            }
    
            /* process new text in file */
            if (FD_ISSET(rst,&iset))
            {
                while (!output())
                    ;
    #endif /*NOSELECT*/
    Last edited by Overworked_PhD; 06-20-2008 at 10:04 PM.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Why wouldn't a system have at least select(), or epoll(), or kpoll(), or some means of selecting an active socket? I can't think of any system that doesn't provide some means of async I/O.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Banned
    Join Date
    May 2007
    Location
    Berkeley, CA
    Posts
    329
    In regards to select(), some older versions of Solaris implement select() using poll() as opposed to having a select() system call.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    So? Is there some debilitating shortcoming in this?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. select, named pipe and O_RDONLY
    By alexfranci in forum Linux Programming
    Replies: 8
    Last Post: 06-14-2009, 04:10 PM
  2. A fifo file and select() problem
    By itsdafoetime in forum C Programming
    Replies: 2
    Last Post: 03-08-2009, 01:23 AM
  3. Using select() for writing
    By StanleyC in forum Networking/Device Communication
    Replies: 4
    Last Post: 06-02-2004, 07:44 AM
  4. Very odd segmentation fault/core dump.
    By ChristianTool in forum C Programming
    Replies: 19
    Last Post: 04-26-2004, 06:38 AM
  5. Where is a good place to start?!
    By bobthefish3 in forum Game Programming
    Replies: 1
    Last Post: 10-09-2001, 11:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21