lkml.org 
[lkml]   [2002]   [Oct]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: and nicer too - Re: [PATCH] epoll more scalable than poll
    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/

    \
     
     \ /
      Last update: 2005-03-22 13:30    [W:6.901 / U:0.444 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site