By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,045 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,045 IT Pros & Developers. It's quick & easy.

How does the file descriptor work on given C code

P: 55
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 .

Expand|Select|Wrap|Line Numbers
  1. if (misc->playing == -1 || misc->cd_type != CDIO_DISC_MODE_CD_DA)
  2.       {
  3.          fd_set rfds;
  4.          struct timeval tv;
  5.  
  6.          FD_ZERO (&rfds);
  7.          FD_SET (0, &rfds);
  8.          tv.tv_sec = 0;
  9.          tv.tv_usec = 100000;
  10. // pause till a key has been pressed or 0.1 misc->elapsed_seconds are elapsed
  11.          select (1, &rfds, NULL, NULL, &tv);
  12.       } // if
  13.  
Please waiting for your fast response.

Thanks
Anes P A
Jan 6 '16 #1
Share this Question
Share on Google+
4 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
Have you read about:

Expand|Select|Wrap|Line Numbers
  1. 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.
Jan 6 '16 #2

Expert 100+
P: 2,398
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.
Jan 6 '16 #3

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

Thanks
Anes
Jan 7 '16 #4

Expert 100+
P: 2,398
Your code snippet is very similar to the example in the Ubuntu man page for select, et.al.. What questions remain after reading this?
Jan 7 '16 #5

Post your reply

Sign in to post your reply or Sign up for a free account.