Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] file descriptors as integers?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Fabrice Le Fessant <fabrice@l...>
Subject: Re: [Caml-list] file descriptors as integers?

>  The Unix module publishes the type "file_descr" as an abstract type.
>  This makes it difficult to use file descriptors in some (IMHO) useful
>  ways.
>  
>  When I manage a large number of descriptors, an efficient technique to
>  is to use the descriptor as the index into an array of per-connection
>  data structures.  But since the descriptor is abstract, I cannot use
>  it as an integer to do this.
>  
>  I know I can use hash-tables in ocaml to create a similar relationship
>  between (fd,data) but it is less efficient.  Is there any kind of
>  interface to get the integral value of a file descriptor, or perhaps a
>  more encapsulated way to accomplish a similar result?

I don't see why you cannot put the file_descr in a bigger structure
with another counter, and use this counter instead of the file_descr
number. Anyway, this beautiful function should do the trick (at least,
on Unix systems): 

let fd_num (fd : Unix.file_descr)= (Obj.magic fd : int)

- Fabrice

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners