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 12:14:13 +0200	[thread overview]
Message-ID: <20130511101412.GH3334@frosties> (raw)
In-Reply-To: <1368265499.5134.0@samsung>

On Sat, May 11, 2013 at 11:44:59AM +0200, Gerd Stolpmann wrote:
> Am 11.05.2013 01:10:41 schrieb(en) Goswin von Brederlow:
> >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.
> 
> Using a hashtbl or other external container is the right thing to
> do. You cannot put an OCaml pointer into a kernel structure, because
> the OCaml memory manager might want to move the OCaml block around,
> and there is no way to update the pointer when OCaml wants to do
> this. So you cannot get around this indirection here (which is also
> very cheap at runtime, so I also wonder where the runtime
> improvement would be).
> 
> Gerd

It is true that one needs an indirection to keep the GC happy. But
that would be something for the Epoll module to handle. Not for me.
Wether it does that in the ocaml code or in the C stubs is open to
implementation.

The improvement would be not to have to manage the hashtbl manually at
every place where the epoll set is modified.

> >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

MfG
	Goswin

  reply	other threads:[~2013-05-11 10:14 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
2013-05-11  9:44     ` AW: " Gerd Stolpmann
2013-05-11 10:14       ` Goswin von Brederlow [this message]
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=20130511101412.GH3334@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).