public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Davide Libenzi <davidel@xmailserver.org>
To: Dan Kegel <dank@kegel.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	"Christopher K. St. John" <cks@distributopia.com>
Subject: Re: [PATCH] /dev/epoll update ...
Date: Wed, 19 Sep 2001 19:28:04 -0700 (PDT)	[thread overview]
Message-ID: <XFMail.20010919192804.davidel@xmailserver.org> (raw)
In-Reply-To: <3BA950AF.58CFCF29@kegel.com>


On 20-Sep-2001 Dan Kegel wrote:
> Davide Libenzi wrote:
>> 1)      if (recv()/send() == FAIL)
>> 2)              ioctl(EP_POLL);
> 
> A lot of people, including me, were under the mistaken impression
> that /dev/epoll, like /dev/poll, provided an efficient way to
> retrieve the current readiness state of fd's.  I understand from your post
> that /dev/epoll's purpose is to retrieve state changes; in other
> words, it's exactly like F_SETSIG/F_SETOWN/O_ASYNC except that
> the readiness change indications are picked up via an ioctl
> rather than via a signal.
> 
> A scorecard for the confused (Davide, correct me if I'm wrong):
> 
> * API's that allow you to retrieve the current readiness state of
>   a set of fd's:  poll(), select(), /dev/poll, kqueue().
>   Buzzwords describing this kind of interface: level-triggered, multishot.
> 
> * API's that allow you to retrieve *changes* to the readiness state of
>   a set of fd's: F_SETSIG/F_SETOWN/O_ASYNC + sigtimedwait(), /dev/epoll, kqueue().
>   Buzzwords describing this kind of interface: edge-triggered, single-shot.
> 
> (Note that kqueue is in both camps.)
> 
> Er, I guess that means I'll rip up the /dev/epoll support I based on my
> /dev/poll code, and replace it with some based on my O_ASYNC code...


Exactly :)
Here are examples basic functions when used with coroutines :


int dph_connect(struct dph_conn *conn, const struct sockaddr *serv_addr, socklen_t addrlen) {

        if (connect(conn->sfd, serv_addr, addrlen) == -1) {
                if (errno != EWOULDBLOCK && errno != EINPROGRESS)
                        return -1;
                conn->events = POLLOUT | POLLERR | POLLHUP;
                co_resume(conn);
                if (conn->revents & (POLLERR | POLLHUP))
                        return -1;
        }
        return 0;
}

int dph_read(struct dph_conn *conn, char *buf, int nbyte) {
        int n;

        while ((n = read(conn->sfd, buf, nbyte)) < 0) {
                if (errno == EINTR)
                        continue;
                if (errno != EAGAIN && errno != EWOULDBLOCK)
                        return -1;
                conn->events = POLLIN | POLLERR | POLLHUP;
                co_resume(conn);
        }
        return n;
}

int dph_write(struct dph_conn *conn, char const *buf, int nbyte) {
        int n;

        while ((n = write(conn->sfd, buf, nbyte)) < 0) {
                if (errno == EINTR)
                        continue;
                if (errno != EAGAIN && errno != EWOULDBLOCK)
                        return -1;
                conn->events = POLLOUT | POLLERR | POLLHUP;
                co_resume(conn);
        }
        return n;
}

int dph_accept(struct dph_conn *conn, struct sockaddr *addr, int *addrlen) {
        int sfd;

        while ((sfd = accept(conn->sfd, addr, (socklen_t *) addrlen)) < 0) {
                if (errno == EINTR)
                        continue;
                if (errno != EAGAIN && errno != EWOULDBLOCK)
                        return -1;
                conn->events = POLLIN | POLLERR | POLLHUP;
                co_resume(conn);
        }
        return sfd;
}




- Davide


  reply	other threads:[~2001-09-20  2:24 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-19  2:20 [PATCH] /dev/epoll update Dan Kegel
2001-09-19  6:25 ` Dan Kegel
2001-09-19  7:04 ` Christopher K. St. John
2001-09-19 15:37   ` Dan Kegel
2001-09-19 15:59     ` Zach Brown
2001-09-19 17:12     ` Christopher K. St. John
2001-09-19 17:39     ` Davide Libenzi
2001-09-19 18:26     ` Alan Cox
2001-09-19 17:25   ` Davide Libenzi
2001-09-19 19:03     ` Christopher K. St. John
2001-09-19 19:30       ` Davide Libenzi
2001-09-19 21:49         ` Christopher K. St. John
2001-09-19 22:11           ` Davide Libenzi
2001-09-19 23:24             ` Christopher K. St. John
2001-09-19 23:52               ` Davide Libenzi
2001-09-20  2:13             ` Dan Kegel
2001-09-20  2:28               ` Davide Libenzi [this message]
2001-09-20  3:03                 ` Dan Kegel
2001-09-20 16:58                   ` Davide Libenzi
2001-09-20  4:32                 ` Christopher K. St. John
2001-09-20  4:43                   ` Christopher K. St. John
2001-09-20  5:05                     ` Benjamin LaHaise
2001-09-20 18:25                       ` Davide Libenzi
2001-09-20 19:33                         ` Benjamin LaHaise
2001-09-20 19:58                           ` Davide Libenzi
2001-09-20 17:18                   ` Davide Libenzi
2001-09-24  0:11                     ` Gordon Oliver
2001-09-24  0:33                       ` Davide Libenzi
2001-09-24 19:23                     ` Eric W. Biederman
2001-09-24 20:04                       ` Davide Libenzi
2001-09-21  5:59             ` Ton Hospel
2001-09-21 16:48               ` Davide Libenzi
2001-09-19 17:21 ` Davide Libenzi
  -- strict thread matches above, loose matches on Subject: below --
2002-03-20  3:49 [patch] " Davide Libenzi
     [not found] <local.mail.linux-kernel/3BB03C6A.7D1DD7B3@kegel.com>
     [not found] ` <local.mail.linux-kernel/3BAEB39B.DE7932CF@kegel.com>
     [not found]   ` <local.mail.linux-kernel/3BAF83EF.C8018E45@distributopia.com>
2001-09-25 17:36     ` [PATCH] " Jonathan Lemon
2001-09-25 18:34       ` Dan Kegel
2001-09-24  4:16 Dan Kegel
2001-09-24 19:11 ` Eric W. Biederman
2001-09-24 19:34   ` Jamie Lokier
2001-09-24 20:09     ` Davide Libenzi
2001-09-24 21:56       ` Jamie Lokier
2001-09-24 22:08         ` Davide Libenzi
2001-09-24 22:09           ` Jamie Lokier
2001-09-24 22:20             ` Davide Libenzi
2001-09-24 22:21               ` Jamie Lokier
2001-09-24 22:30                 ` Davide Libenzi
2001-09-25  9:25             ` Dan Kegel
     [not found] ` <3BAF83EF.C8018E45@distributopia.com>
2001-09-25  8:12   ` Dan Kegel
2001-09-21  6:22 Dan Kegel
2001-09-21 18:45 ` Davide Libenzi
2001-09-07 19:27 Davide Libenzi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=XFMail.20010919192804.davidel@xmailserver.org \
    --to=davidel@xmailserver.org \
    --cc=dank@kegel.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox