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
Select on channels (again)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-08-22 (08:21)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] Re: Select on channels (again)
From: "Nathaniel Gray" <n8gray@gmail.com>
> On 8/21/06, Jonathan Roewen <jonathan.roewen@gmail.com> wrote:
> > Why can't you just use the unix file opening functions since you're
> > using unix select? And if you need the ocaml in/out channels, convert
> > the unix file descriptors to ocaml ones instead of the other way
> > around. Seems simple enough to me.
> It sounds simple but doesn't work.  If select tells you a file
> descriptor doesn't have data waiting you can't be sure there isn't
> still data in the corresponding channel's buffer.  See the thread that
> I referenced for a good discussion of why this is annoying.  For one
> thing, it makes it impossible to use Marshal.from_channel without
> potentially blocking.

(I didn't follow the discussion, so I may misunderstand...)

The problem with Marshal.from_channel seems independent of channel
buffering. The point is that Marshal.from_channel cannot work in
non-blocking mode, as it doesn't know in advance how many bytes it
will need to obtain a well-formed value. The only way I see is to do
the buffering yourself, and extract the data using Marshal.from_string
and Marshal.total_size.

Jacques Garrigue