Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6963693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:49:38+00:00 2026-05-27T15:49:38+00:00

According to this article poll vs select vs event-based : select() only uses (at

  • 0

According to this article poll vs select vs event-based:

select() only uses (at maximum) three bits of data per file
descriptor, while poll() typically uses 64 bits per file descriptor.
In each syscall invoke poll() thus needs to copy a lot more over to
kernel space. A small win for select().

Here is the implementation of fd_set (found on Advisories : multiple applications fd_set structure bitmap array index overflow

#ifndef FD_SETSIZE
#define FD_SETSIZE  1024
#endif
#define NBBY    8       /* number of bits in a byte */
typedef long    fd_mask;
#define NFDBITS (sizeof (fd_mask) * NBBY)   /* bits per mask */
#define howmany(x,y)    (((x)+((y)-1))/(y))
typedef struct _types_fd_set {
    fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
} _types_fd_set;

#define fd_set _types_fd_set

So, in the end, fd_set is just an array of long. It is also written:

A call to FD_SET sets a bit to 1 using socket number as an index:

which means, if I got a socket fd number 5, the element indexed 5 will be seleted, and its first bit will be flipped from 0 to 1. Since select() uses 3 bits, I guess the other two bits are for sending and receive. Is this correct? Why does select() use a long when it only needs 3 bits?

Also, stated above, poll() uses 64 bits for checking. Why does poll need to check every bit in pollfd struct? Here is the pollfd struct:

struct pollfd {
    int fd;         // the socket descriptor
    short events;   // bitmap of events we're interested in
    short revents;  // when poll() returns, bitmap of events that occurred
};

The total bits in the struct is 64 bits, for a 32-bit int and two 16-bit short. I know the usual way of checking a bit flag is using AND (&) operator to filter out other irrelevant bits. Does that apply to this case?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:49:38+00:00Added an answer on May 27, 2026 at 3:49 pm

    It doesn’t use 1 long per se. It uses a bit field of FD_SETSIZE bits, in this case 32 32 bits longs or 16 64 bits longs. By using longs, it allows to use less memory operations on 64 bit machines (which are widespread on Unix already for 20 years). They could have used normal int but then they wouldn’t have had an advantage on 64 bit machines. It’s only forward thinking.

    If you used select on several file descriptors you need the room for all the file descriptors. Imagine you want to read from 3 sockets, from a SCSI device and a file and the file descriptor values are respectively 3, 7, 10, 12 and 67, how would you represent that? Use a bitset where the bit with that number is set.

     00010001.00101000:00000000.00000000:00000000.00000000:00000000.00000000   00010000.00000000
        ^   ^   ^ ^                                                               ^
        0   0   1 1                                                               6 
        3   7   0 2                                                               7 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According this MSDN article HttpApplication .EndRequest can be used to close or dispose of
According to this article Silverlight 2 Beta 2 supports the DataContractJsonSerializer object. But, when
According to this article rebasing is not necessary for .NET assemblies due to JIT
According to this article , it's possible to get multiline XML comments -- instead
According to this article about writing shell extensions in .Net, inheriting the shell interfaces
I've got a PHP-fpm setup on nginx setup according to this article: http://interfacelab.com/nginx-php-fpm-apc-awesome/ PHP
I implemented Dynamic DataSource Routing for Spring+Hibernate according to this article . I have
I'm trying to set up hudson with git according to this article , but
According to this MSDN article about medium trust , under medium-trust: FileIOPermission is restricted.
According to this Mozilla article on Ogg media , media works more seamlessly in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.