Re: and nicer too - Re: [PATCH] epoll more scalable than poll

Davide Libenzi (davidel@xmailserver.org)
Mon, 28 Oct 2002 15:23:10 -0800 (PST)


On Mon, 28 Oct 2002, bert hubert wrote:

> The interface is also lovely:
>
> for(;;) {
> nfds = sys_epoll_wait(kdpfd, &pfds, -1);
> fprintf(stderr,"sys_epoll_wait returned: %d\n",nfds);
>
> for(n=0;n<nfds;++n) {
> if(pfds[n].fd==s) {
> client=accept(s, (struct sockaddr*)&local, &addrlen);
>
> if(client<0){
> perror("accept");
> continue;
> }
> if (sys_epoll_ctl(kdpfd, EP_CTL_ADD, client, POLLIN ) < 0) {
> fprintf(stderr, "sys_epoll set insertion error: fd=%d\n", client);
> return -1;
> }
> }
> else
> printf("something happened on fd %d\n", pfds[n].fd);
> }
> }

This is how you probably want to use it :

for(;;) {
nfds = sys_epoll_wait(kdpfd, &pfds, -1);

for(n = 0; n < nfds; ++n) {
if(fd = pfds[n].fd) == s) {
client = accept(s, (struct sockaddr*)&local, &addrlen);
if(client < 0){
perror("accept");
continue;
}
if (sys_epoll_ctl(kdpfd, EP_CTL_ADD, client, POLLIN ) < 0) {
fprintf(stderr, "sys_epoll set insertion error: fd=%d\n", client);
return -1;
}
fd = client;
}

do_use_fd(fd);
}
}

- Davide

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/