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

Davide Libenzi
2002-10-28T23:07:28Z

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