English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Help interfacing with C
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-08-18 (02:41)
From: Bardur Arantsson <spam@s...>
Subject: Re: Help interfacing with C
Nathaniel Gray wrote:
> Hi folks,
> have select work on (file_descr * 'a) pairs instead of plain file
> descriptors.

It's much easier than that; just define a conversion in OCaml:

    external file_descr_to_int : file_descr -> int = "%identity";
    external int_to_file_descr : int -> file_descr = "%identity";

and use

    let my_select r w e t =
       let r' = List.map file_descr_to_int r
       and w' = List.map file_descr_to_int w
       and e' = List.map file_descr_to_int e
         Unix.select r' w' e' t;;

You seem to be doing the mapping of the result values, but that is just 
a question of mapping int_to_file_descr over the result lists.

Of course this may be rather slower than your version, but Unix.select 
is very very slow anyway since it's allocating at least one list for 
every single call... and iterating through all(?) the file descriptors 
in the input FD_SETs as well.

[Shameless plug below: If you want better performance, you might want
to try


I must warn you, though, that there are no timers or signal handling: It 
turned out I didn't them for my particular application, so I haven't 
bothered adding support. The actual FD polling/selection has worked very 
reliably for me.]

Bardur Arantsson

The truth is out there, but lies are in your head.
                                      Terry Pratchett, 'Hogfather'