How does the file descriptor work on given C code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amskape
    New Member
    • Apr 2010
    • 56

    How does the file descriptor work on given C code

    I am new to C programming file descriptor concept , working in an already developed code base. I have no idea regarding the following file descriptor concept .

    Code:
    if (misc->playing == -1 || misc->cd_type != CDIO_DISC_MODE_CD_DA)
          {
             fd_set rfds;
             struct timeval tv;
    
             FD_ZERO (&rfds);
             FD_SET (0, &rfds);
             tv.tv_sec = 0;
             tv.tv_usec = 100000;
    // pause till a key has been pressed or 0.1 misc->elapsed_seconds are elapsed
             select (1, &rfds, NULL, NULL, &tv);
          } // if
    Please waiting for your fast response.

    Thanks
    Anes P A
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Have you read about:

    Code:
    select (1, &rfds, NULL, NULL, &tv);

    The select function appears in various forms of socket programming. I know there is a Wikipedia for the UNIX version of this function written by the Open Group which has a lot more info than I can post here.

    Check it out.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      Type fd_set and functions FD_ZERO(), FD_SET(), and select() are not part of the C Standard. Presumably they are provided by the operating system.
      What operating system are you using?

      Your operating system may vary, but typically the return value from select() is useful.

      Comment

      • amskape
        New Member
        • Apr 2010
        • 56

        #4
        Dear donbock,
        I am using Ubuntu 15.10. The application is a C written program running in ubuntu...
        advise me

        Thanks
        Anes

        Comment

        • donbock
          Recognized Expert Top Contributor
          • Mar 2008
          • 2427

          #5
          Your code snippet is very similar to the example in the Ubuntu man page for select, et.al.. What questions remain after reading this?

          Comment

          Working...