Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: -- (:)
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' = file_descr_to_int r
       and w' = file_descr_to_int w
       and e' = file_descr_to_int e
       in 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 
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'