Browse thread
Select on channels (again)
[
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: | 2006-08-23 (05:27) |
From: | Nathaniel Gray <n8gray@g...> |
Subject: | Re: [Caml-list] Re: Select on channels (again) |
On 8/22/06, Olivier Andrieu <oandrieu@nerim.net> wrote: > Nathaniel Gray [Monday 21 August 2006] : > > > > 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. > > Indeed, Marshal.from_channel would block, but it's not the only way to > read a marshalled value: cf. Marshal.header_size and > Marshal.data_size. > > With these, you can read your marshalled value from file_descr into a > buffer in a non-blocking, select-compatible way and then use > Marshal.from_string. Yes, as I said, it's possible to work around this limitation by creating yet another implementation of buffered I/O. My point is that there's already a good buffered I/O implementation in ocaml that could suit many (but not all) needs -- channels. Adding channel_select would make channels a lot more useful at very little expense. Heck, I would be satisfied with in/out_channel_is_ready, which would be even easier! Cheers, -n8 -- >>>-- Nathaniel Gray -- Caltech Computer Science ------> >>>-- Mojave Project -- http://mojave.cs.caltech.edu -->