* [Caml-list] Linux epoll bindings @ 2013-05-08 14:50 Goswin von Brederlow 2013-05-08 15:06 ` Jeremie Dimino ` (3 more replies) 0 siblings, 4 replies; 8+ messages in thread From: Goswin von Brederlow @ 2013-05-08 14:50 UTC (permalink / raw) To: caml-list Hi, does anyone have or know of bindings for linux epoll for ocaml? MfG Goswin ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Linux epoll bindings 2013-05-08 14:50 [Caml-list] Linux epoll bindings Goswin von Brederlow @ 2013-05-08 15:06 ` Jeremie Dimino 2013-05-08 15:06 ` Markus Mottl ` (2 subsequent siblings) 3 siblings, 0 replies; 8+ messages in thread From: Jeremie Dimino @ 2013-05-08 15:06 UTC (permalink / raw) To: Goswin von Brederlow; +Cc: caml-list Hi, Core has bindings for epoll. They are in the module Core.Std.Linux_ext.Epoll. Jeremie On Wed, May 8, 2013 at 10:50 AM, Goswin von Brederlow <goswin-v-b@web.de> wrote: > does anyone have or know of bindings for linux epoll for ocaml? ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Linux epoll bindings 2013-05-08 14:50 [Caml-list] Linux epoll bindings 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-08 15:54 ` Prashanth Mundkur 2013-05-08 18:15 ` AW: " Gerd Stolpmann 3 siblings, 1 reply; 8+ messages in thread From: Markus Mottl @ 2013-05-08 15:06 UTC (permalink / raw) To: Goswin von Brederlow; +Cc: caml-list 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 > > -- > 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 -- Markus Mottl http://www.ocaml.info markus.mottl@gmail.com ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Linux epoll bindings 2013-05-08 15:06 ` Markus Mottl @ 2013-05-10 23:10 ` Goswin von Brederlow 2013-05-11 9:44 ` AW: " Gerd Stolpmann 0 siblings, 1 reply; 8+ messages in thread From: Goswin von Brederlow @ 2013-05-10 23:10 UTC (permalink / raw) To: caml-list 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* AW: [Caml-list] Linux epoll bindings 2013-05-10 23:10 ` Goswin von Brederlow @ 2013-05-11 9:44 ` Gerd Stolpmann 2013-05-11 10:14 ` Goswin von Brederlow 0 siblings, 1 reply; 8+ messages in thread From: Gerd Stolpmann @ 2013-05-11 9:44 UTC (permalink / raw) To: Goswin von Brederlow; +Cc: caml-list 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 > > 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 > > -- > 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 > > -- ------------------------------------------------------------ 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 ------------------------------------------------------------ ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Linux epoll bindings 2013-05-11 9:44 ` AW: " Gerd Stolpmann @ 2013-05-11 10:14 ` Goswin von Brederlow 0 siblings, 0 replies; 8+ messages in thread From: Goswin von Brederlow @ 2013-05-11 10:14 UTC (permalink / raw) To: caml-list 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Linux epoll bindings 2013-05-08 14:50 [Caml-list] Linux epoll bindings Goswin von Brederlow 2013-05-08 15:06 ` Jeremie Dimino 2013-05-08 15:06 ` Markus Mottl @ 2013-05-08 15:54 ` Prashanth Mundkur 2013-05-08 18:15 ` AW: " Gerd Stolpmann 3 siblings, 0 replies; 8+ messages in thread From: Prashanth Mundkur @ 2013-05-08 15:54 UTC (permalink / raw) To: Goswin von Brederlow; +Cc: caml-list On 16:50 Wed 08 May, Goswin von Brederlow wrote: > does anyone have or know of bindings for linux epoll for ocaml? There are some in sonet too: https://github.com/pmundkur/sonet/blob/master/eventloop/epoll_stubs.c ^ permalink raw reply [flat|nested] 8+ messages in thread
* AW: [Caml-list] Linux epoll bindings 2013-05-08 14:50 [Caml-list] Linux epoll bindings Goswin von Brederlow ` (2 preceding siblings ...) 2013-05-08 15:54 ` Prashanth Mundkur @ 2013-05-08 18:15 ` Gerd Stolpmann 3 siblings, 0 replies; 8+ messages in thread From: Gerd Stolpmann @ 2013-05-08 18:15 UTC (permalink / raw) To: Goswin von Brederlow; +Cc: caml-list Am 08.05.2013 16:50:45 schrieb(en) Goswin von Brederlow: > Hi, > > does anyone have or know of bindings for linux epoll for ocaml? There is also some support in Ocamlnet: http://projects.camlcity.org/projects/dl/ocamlnet-3.6.3/doc/html-main/Netsys_posix.html#1_Eventaggregation Gerd > MfG > Goswin > > -- > 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 > > -- ------------------------------------------------------------ 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 ------------------------------------------------------------ ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2013-05-11 10:14 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2013-05-08 14:50 [Caml-list] Linux epoll bindings 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 2013-05-08 15:54 ` Prashanth Mundkur 2013-05-08 18:15 ` AW: " Gerd Stolpmann
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox