Browse thread
Help interfacing with C
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ 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,
[--snip--]
> 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
in
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
http://www.imada.sdu.dk/~bardur/personal/45-programs/ocaml-events/ocaml-events-0.1.0.tar.bz2
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
<bardurREMOVE@THISscientician.net>
The truth is out there, but lies are in your head.
Terry Pratchett, 'Hogfather'