Select() + UDP resulting in too many open files

这一生的挚爱 提交于 2021-01-28 05:06:07

问题


I currently have a select() statement configured to keep track of two UDP sockers. I send perhaps 10 - 20 messages a second at one general data socket, which is this interpreted as I expected.

However, once I hit around 1024 messages, I get the notice:

talker: socket: Too many open files talker: failed to bind socket

This is logical to me, since ulimit -n shows a max of 1024 open files for this user. However, why are there all of these open files? With UDP, there is no connection made, so I do not believe I need to be closing a socket each time (although perhaps I'm wrong).

Any ideas? Thanks in advance.


回答1:


I think in this case "Too many open files" really means you've hit the file descriptor limit; network sockets count towards this limit. Are you sure that there's nothing else - say in routehelper - that's creating further sockets?

What platform are you running on? If Linux, lsof or grobbling around in /proc/<pid>/fd - while it's running, before it hits the limit - might illustrate where all the fds are going.

Tip: Don't rely on socket_udp_inboundALL being numerically larger than socket_udp_inboundRC - it's better to explicitly compare their values at least once.




回答2:


If you are on Linux do an strace(1) on the client to check for the socket(2) and open(2) vs close(2) system calls (try -e trace=socket,open,close option). This is the easiest way to balance the file descriptor count at this point.



来源:https://stackoverflow.com/questions/3136038/select-udp-resulting-in-too-many-open-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!