select() max sockets

前端 未结 4 1726
感动是毒
感动是毒 2021-01-13 10:43

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

相关标签:
4条回答
  • 2021-01-13 10:54

    If you are programming under a Posix compliant system, you should be able to use the poll() function instead of select() and this will do away with the limit that you mention. Alternatively, you can call select() multiple times in succession but be certain to use a relatively short timeout.

    0 讨论(0)
  • 2021-01-13 11:10

    You don't say what OS you're using, but for most, if you want to use file descriptors above 1024 with select, you can #define FD_SETSIZE to be a larger number BEFORE #including sys/socket.h. Unfortunately, this doesn't work on Linux.

    0 讨论(0)
  • 2021-01-13 11:11

    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.

    0 讨论(0)
  • 2021-01-13 11:13

    For really large numbers of sockets look into using a library like libevent.

    The library can abstract several OS-specific advanced features like /dev/poll, kqueue, epoll, and event ports. With these you can handle really vast numbers of connections.

    0 讨论(0)
提交回复
热议问题