From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 817ED7EE51 for ; Sat, 11 May 2013 11:45:03 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of info@gerd-stolpmann.de) identity=pra; client-ip=212.227.17.9; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="info@gerd-stolpmann.de"; x-sender="info@gerd-stolpmann.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of info@gerd-stolpmann.de) identity=mailfrom; client-ip=212.227.17.9; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="info@gerd-stolpmann.de"; x-sender="info@gerd-stolpmann.de"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of postmaster@moutng.kundenserver.de designates 212.227.17.9 as permitted sender) identity=helo; client-ip=212.227.17.9; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="info@gerd-stolpmann.de"; x-sender="postmaster@moutng.kundenserver.de"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AggBAIoSjlHU4xEJlGdsb2JhbABZgz6tf5IjfRYOAQEBAQcNCQkUAyWCHwEBBAEnEzQLQF0JEgYTCQmHaAMJCgi0DwOIMhaJEIVcJgeDVQOOSYoJkyA X-IPAS-Result: AggBAIoSjlHU4xEJlGdsb2JhbABZgz6tf5IjfRYOAQEBAQcNCQkUAyWCHwEBBAEnEzQLQF0JEgYTCQmHaAMJCgi0DwOIMhaJEIVcJgeDVQOOSYoJkyA X-IronPort-AV: E=Sophos;i="4.87,652,1363129200"; d="scan'208";a="16859019" Received: from moutng.kundenserver.de ([212.227.17.9]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 11 May 2013 11:45:03 +0200 Received: from office1.lan.sumadev.de (dslb-094-219-217-035.pools.arcor-ip.net [94.219.217.35]) by mrelayeu.kundenserver.de (node=mrbap1) with ESMTP (Nemesis) id 0MfjHQ-1Uw3YH2ry8-00NGcM; Sat, 11 May 2013 11:45:02 +0200 Received: from samsung (546BF816.cm-12-4d.dynamic.ziggo.nl [84.107.248.22]) by office1.lan.sumadev.de (Postfix) with ESMTPSA id 280F3C00CF; Sat, 11 May 2013 11:45:01 +0200 (CEST) Date: Sat, 11 May 2013 11:44:59 +0200 From: Gerd Stolpmann To: Goswin von Brederlow Cc: caml-list@inria.fr In-Reply-To: <20130510231041.GA29570@frosties> (from goswin-v-b@web.de on Sat May 11 01:10:41 2013) X-Mailer: Balsa 2.4.11 Message-Id: <1368265499.5134.0@samsung> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; DelSp=Yes; Format=Flowed Content-Disposition: inline Content-Transfer-Encoding: quoted-printable X-Provags-ID: V02:K0:NWtCyHK+fllZlY+qzZIIoVdJvEXWIwcdZ1+W7UaYqaz QaszBSb9rGRx3Q968RUhbWpEDaQIYYa4QRFGK9un484RAyN+aj IqGY48eOlSHlgBm+t9lFGPBTiY4y+WASa4waOyfGTie1iqCLVG TQXyoMbUuJKgx3plnGXjcbXojaNkL4Qs4ISG0pdAe0cb93RxF4 znpqZMKxdnBE57sQb4vlbfN2bK0ozeZo8+BtSAFN/K4KlSAdiT 0+t8WKPYbVJb18xYsfs4yBqmP2r+mPKHChR8FZqHwvg5o2GZbk ahHgt23fjcgMiAlPtZyvPMiL2T2WEweQKD3JXT3QxMSMYQ/+jy kiqVUcy0tzurLVdYiZo0= Subject: AW: [Caml-list] Linux epoll bindings 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. >=20 > 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.=20=20 You cannot put an OCaml pointer into a kernel structure, because the=20=20 OCaml memory manager might want to move the OCaml block around, and=20=20 there is no way to update the pointer when OCaml wants to do this. So=20=20 you cannot get around this indirection here (which is also very cheap=20=20 at runtime, so I also wonder where the runtime improvement would be). Gerd >=20 > 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): >=20 > module Epoll: sig > type op =3D ADD | MOD | DEL >=20 > type flags (* EPOLLIN | EPOLLOUT | .... *) >=20 > type 'a event =3D { > flags : flags; > data : 'a > } >=20 > type 'a t >=20 > val create : 'a. (int -> 'a t) > (** create max_events creates an epoll object able to process up > to max_events per wait call. *) >=20 > val ctl : 'a t -> op -> Unix.file_descr -> 'a event -> unit > (** ctl t op fd event adds, modifies, deletes the association=20=20 > between > the fd and the event. *) >=20 > 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=20=20 > timeout > passes. *) >=20 > 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 >=20 >=20 > Anyone know of epoll bindings like that? I only found the FD kind with > google. >=20 > MfG > Goswin >=20 > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs >=20 >=20 --=20 ------------------------------------------------------------ Gerd Stolpmann, Darmstadt, Germany gerd@gerd-stolpmann.de Creator of GODI and camlcity.org. Contact details: http://www.camlcity.org/contact.html Company homepage: http://www.gerd-stolpmann.de ------------------------------------------------------------=