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 8800925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:43:04+00:00 2026-06-14T00:43:04+00:00

In a server/client setup I have a server connecting with clients on a handful

  • 0

In a server/client setup I have a server connecting with clients on a handful (at the moment 4) of different sockets. At the moment I use select with a calculated set_size, but what are the upper limit, before it is worthwhile to use FD_SETSIZE instead?

Below are some code examples to illustrate the point. First building the set:

FD_ZERO(&set);
FD_SET(socket1, &set);
FD_SET(socket2, &set);
FD_SET(socket3, &set);
FD_SET(socket4, &set);

Here is how the set_size is calculated:

set_size = MAX(socket1, socket2);
set_size = MAX(set_size, socket 3);
set_size = MAX(set_size, socket4);
set_size += 1;

And the usage:

while ((cnt = select(set_size, &set, NULL, NULL, &t)) != -1 || errno == EINTR) {
    if (cnt > 0)
        // Do different stuff depending what socket is active
    else
        // Keep everything alive and add the sockets to the set again
}

Recently I had to add a two new sockets and I might need to add more in the future. When would you use FD_SETSIZE as opposed to the calculated set_size?

  • 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-06-14T00:43:05+00:00Added an answer on June 14, 2026 at 12:43 am

    I have never worried about this because it seems like it would make a very small difference compared to the performance penalty for using select() in the first place.

    Having said that, I think it’s always worth calculating the correct value, because it’s not very expensive to calculate: if you keep the current set_size in a local variable as you propose, it’s O(1) with a very low constant each time you add an fd (namely, a compare and possibly an update). Removing an fd is also O(1) except it it’s the last one in the list (in which case it’s O(set_size) but usually better). On the other hand, NOT calculating the set_size means that the kernel has to traverse all FD_SETSIZE entries every single time you call select. Since set_size is probably quite a bit smaller than FD_SETSIZE, it pays to supply the smaller value. Even if set_size is close to FD_SETSIZE, calculating set_size is so cheap that it’s probably almost always still worth it.

    Of course if you’re worried about performance to this extent, you need to be looking at poll() instead of select(). Better yet, you need to be looking at epoll and kqueue, except that’s not portable since those functions are only available on Linux and FreeBSD (including MacOS) respectively.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple client/server setup. The server is in C and the client
I have successfully built a thin client/server using Qt's Tcp Sockets API. I know
I have a TCP client-server setup where I need to be able to pass
Currently we have a hybrid ASP/PHP setup connecting to a SQL Server 2005 database.
I'm going to setup a small client/server server in TCP/IP mode, I use VS2010,C#
I basically have a server set up and I'm accepting new clients(UNIX) and i'm
The following is the setup: Server Client | | accept connect | | v
I was trying to setup remote jmeter server and jmeter client. Server public IP
Hello I am new to Git and trying to setup server part and client
I'm working on this project where the client has a virtual server setup. I

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.