Date: Tue, 15 Jul 2008 16:37:00 -0700 From: JINMEI Tatuya / =?ISO-2022-JP?B?GyRCP0BMQEMjOkgbKEI=?= <Jinmei_Tatuya@isc.org> To: Bakul Shah <bakul@bitblocks.com> Cc: freebsd-net@freebsd.org, Kris Kennaway <kris@FreeBSD.org>, Thomas Vogt <freebsdlists@bsdunix.ch> Subject: Re: too many open file descriptors messages since bind 9.4.2-P1 (port dns94) Message-ID: <m2r69ug1nn.wl%Jinmei_Tatuya@isc.org> In-Reply-To: <20080715230917.DAC3B5B46@mail.bitblocks.com> References: <m2skuag4c2.wl%Jinmei_Tatuya@isc.org> <20080715230917.DAC3B5B46@mail.bitblocks.com>
next in thread | previous in thread | raw e-mail | index | archive | help
At Tue, 15 Jul 2008 16:09:17 -0700, Bakul Shah <bakul@bitblocks.com> wrote: > IIRC, when poll() returns n, you only look at the first n > values in the pollfd array so it is a win when you expect a > very small number of fds to be ready. In the select case you > have to test the bit array until you see the last ready fd. % uname -a FreeBSD opt1.jinmei.org 7.0-RC1 FreeBSD 7.0-RC1 #0: Fri Jan 25 15:17:04 PST 2008 root@opt1.jinmei.org:/usr/src/sys/amd64/compile/GENERIC_NOSMP amd64 (please ignore "RC1":-) % cat polltest.c (omitted here, see below) % cc -o polltest polltest.c % ./polltest poll returned: 1 999th socket is ready (fd=1002) Perhaps You're probably confused poll(2) with /dev/poll. The latter behaves as you described (but is not portable as poll(2)). --- JINMEI, Tatuya Internet Systems Consortium, Inc. out put of polltest.c #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <poll.h> main() { int i, n; struct pollfd pfds[1000]; struct sockaddr_in sin; socklen_t sin_len; char buf[16]; memset(pfds, 0, sizeof(pfds)); memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_len = sizeof(sin); inet_pton(AF_INET, "127.0.0.1", &sin.sin_addr); for (i = 0; i < 1000; i ++) { if ((pfds[i].fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { perror("socket"); exit(1); } if (bind(pfds[i].fd, (struct sockaddr *)&sin, sizeof(sin)) < 0) { perror("bind"); exit(1); } pfds[i].events = POLLIN; } sin_len = sizeof(sin); if (getsockname(pfds[999].fd, (struct sockaddr *)&sin, &sin_len) < 0) { perror("getsockname"); exit(1); } if (sendto(pfds[999].fd, buf, sizeof(buf), 0, (struct sockaddr *)&sin, sizeof(sin)) < 0) { perror("sendto"); exit(1); } n = poll(pfds, 1000, -1); printf("poll returned: %d\n", n); for (i = 0; i < 1000; i++) { if ((pfds[i].revents & POLLIN) != 0) { printf("%dth socket is ready (fd=%d)\n", i, pfds[i].fd); } } exit(0); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?m2r69ug1nn.wl%Jinmei_Tatuya>