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 70F6A7EE51 for ; Sat, 11 May 2013 01:10:43 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=pra; client-ip=212.227.15.3; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=mailfrom; client-ip=212.227.15.3; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mout.web.de) identity=helo; client-ip=212.227.15.3; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="postmaster@mout.web.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgMCAAh9jVHU4w8Dm2dsb2JhbABSgz66d4UpexYOAQEBAQEGCwsJFCiCHwEBBScTGzQLGAklDwUNGzSHeQEDE7RFHysNFYgTjFKCXRaCXmEDlUiBY4YEhhCIMw X-IPAS-Result: AgMCAAh9jVHU4w8Dm2dsb2JhbABSgz66d4UpexYOAQEBAQEGCwsJFCiCHwEBBScTGzQLGAklDwUNGzSHeQEDE7RFHysNFYgTjFKCXRaCXmEDlUiBY4YEhhCIMw X-IronPort-AV: E=Sophos;i="4.87,651,1363129200"; d="scan'208";a="16816289" Received: from mout.web.de ([212.227.15.3]) by mail2-smtp-roc.national.inria.fr with ESMTP; 11 May 2013 01:10:43 +0200 Received: from frosties.localnet ([95.208.119.3]) by smtp.web.de (mrweb003) with ESMTPSA (Nemesis) id 0Lmchn-1U29ju3oO3-00ZX7G for ; Sat, 11 May 2013 01:10:41 +0200 Received: from mrvn by frosties.localnet with local (Exim 4.80) (envelope-from ) id 1UawSX-0007rn-B0 for caml-list@inria.fr; Sat, 11 May 2013 01:10:41 +0200 Date: Sat, 11 May 2013 01:10:41 +0200 From: Goswin von Brederlow To: caml-list@inria.fr Message-ID: <20130510231041.GA29570@frosties> References: <20130508145045.GD17923@frosties> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Provags-ID: V02:K0:gvOzVRR4wNKmCsLvuxuCk9vePd7ACyWS6YfYUmLFn+Q 7zlTmkswQDCumcBNL+5FtvJVYszUAyqd/xBrkQQETW7amk6b4a HD+plUcJ6dp44OnDLhIBYpf85ummoBL7y7HNbFnLshXIuTAaEw Yp10TUtS0rn59P33wcWwkyrZdfxY4Q59B4S/DA+EOcNLIxDRbK rkAgeoCrtdjxAIedBWAbg== Subject: Re: [Caml-list] Linux epoll bindings 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 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