Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select() max sockets

Just more asynchronous stuff!

Alright, so I now have a working asynchronous socket program for my main chatting application, and it's working really well! However I have one concern..

While using select() what is the maximum number of file descriptors that I can use in each set? I've read about a limit of 1024...

If that limit is indeed hard coded and I can't FD_SETSIZE the limit any higher, should I spawn another thread once I reach that limit? Or something else? Is this even a concern?

like image 930
ultifinitus Avatar asked Mar 18 '11 20:03

ultifinitus


People also ask

What does select () do in C?

The select() function indicates which of the specified file descriptors is ready for reading, ready for writing, or has an error condition pending.

What is select in socket?

The select function allows you to check on several different sockets or pipes (or any file descriptors at all if you are not on Windows), and do something based on whichever one is ready first.

How do you use Select in socket programming?

You can use the select() call to pass a bit set containing the socket descriptors for the sockets you want checked. The bit set is fixed in size using one bit for every possible socket. Use the nfds parameter to force select() to check only a subset of the allocated socket bit set.

What does select return on timeout?

A timeout value of 0 causes select to return immediately. This behavior is useful in applications that periodically poll their sockets. The arrival of out-of-band data is the only possible exceptional condition. fd_set is a type defined in the <sys/types.


1 Answers

Yes, the FD_SETSIZE has a limit of 1024. You can easily check that by looking at the select.h header. People have tried to increase the limit, but the reports vary from "working" to "crashing" after a while. If you need that many connections, use poll instead.

A very good article to read.

like image 58
Milan Avatar answered Oct 06 '22 08:10

Milan