caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Linux epoll bindings
Date: Sat, 11 May 2013 01:10:41 +0200	[thread overview]
Message-ID: <20130510231041.GA29570@frosties> (raw)
In-Reply-To: <CAP_800qm-W+CPJoTmB5tSPhtT2pZXh8zaN0VROgX1wkcf0q1oA@mail.gmail.com>

On Wed, May 08, 2013 at 11:06:48AM -0400, Markus Mottl wrote:
> Hi,
> 
> the Jane Street Core library has epoll in its Linux extensions module
> (Core.Std.Linux_ext.Epoll).
> 
> Regards,
> Markus
> 
> On Wed, May 8, 2013 at 10:50 AM, Goswin von Brederlow <goswin-v-b@web.de> wrote:
> > Hi,
> >
> > does anyone have or know of bindings for linux epoll for ocaml?
> >
> > MfG
> >         Goswin
> 
> -- 
> Markus Mottl        http://www.ocaml.info        markus.mottl@gmail.com

I think the best feature of Linux epoll is that the struct epoll_event
contains a epoll_data_t where one can store a pointer, int, uint32_t
or uint64_t. Core.Std.Linux_ext.Epoll (and the other epoll bindings)
seem to always store the Unix.file_descr there.

In my case, and probably most cases, I have different FDs in the mix
that need to do different things when their event is triggered. For
example the server socket needs to call accpet() on POLLIN while
client sockets need to (continue to) parse requests. So every FD has a
bit of state associated with it that tells what to do with it. And I
need a Hashtbl.t to lookup the state for each FD that gets an event.


Now wouldn't it be much better to store a 'a in the epoll_data_t
instead of the FD? That would allow storing a Unix.file_descr just
like now, a closure or any other data structure one wishes to
associate with the event being waited for. Something like (loosely
based on janestreets core):

module Epoll: sig
  type op = ADD | MOD | DEL

  type flags (* EPOLLIN | EPOLLOUT | .... *)

  type 'a event = {
    flags : flags;
    data : 'a
  }

  type 'a t

  val create : 'a. (int -> 'a t)
  (** create max_events  creates an epoll object able to process up
      to max_events per wait call. *)

  val ctl : 'a t -> op -> Unix.file_descr -> 'a event -> unit
  (** ctl t op fd event  adds, modifies, deletes the association between
      the fd and the event. *)

  val wait : 'a t -> [ `After of float | `Immediately | `Never ]
                  -> [ `Ok | `Timeout ]
  (** wait t timeout  blocks until at least one file descriptor in t
      is ready for one of the events it is being watched for, or timeout
      passes. *)

  val iter : 'a t -> (flags -> 'a -> unit) -> unit
  val fold : 'a t -> 'b -> ('b -> flags -> 'a -> 'b) -> 'b
  (** iterate or fold over pending events *)
end


Anyone know of epoll bindings like that? I only found the FD kind with
google.

MfG
	Goswin

  reply	other threads:[~2013-05-10 23:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-08 14:50 Goswin von Brederlow
2013-05-08 15:06 ` Jeremie Dimino
2013-05-08 15:06 ` Markus Mottl
2013-05-10 23:10   ` Goswin von Brederlow [this message]
2013-05-11  9:44     ` AW: " Gerd Stolpmann
2013-05-11 10:14       ` Goswin von Brederlow
2013-05-08 15:54 ` Prashanth Mundkur
2013-05-08 18:15 ` AW: " Gerd Stolpmann

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=20130510231041.GA29570@frosties \
    --to=goswin-v-b@web.de \
    --cc=caml-list@inria.fr \
    /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;
as well as URLs for NNTP newsgroup(s).