caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Implementing rollback channels with Ocamlnet
@ 2007-01-10 17:08 Till Varoquaux
  0 siblings, 0 replies; only message in thread
From: Till Varoquaux @ 2007-01-10 17:08 UTC (permalink / raw)
  To: ocaml ml

I need to be able to backtrack while reading a stream. The way I tried
to do it was to build a new in_channel reading from the window of the
previous (buffered) channel.
Here's my current failed attempt:

open Netstream;;

exception BaseChannelAccess

class rollback_chan (is:in_obj_stream) : Netchannels.rec_in_channel=
object
 val mutable p_in=is#pos_in
 val mutable closed=false
 method close_in  () = ()
  method input dest dest_pos len =
  if (is#pos_in != p_in) then
   raise BaseChannelAccess;
  is#want(p_in+len);
  Netbuffer.blit is#window p_in dest dest_pos len;
  p_in <- p_in + len;
  len
end;;

let rollback_chan input=
  Netchannels.lift_in(`Rec (new rollback_chan(input)))

It doesn't work (at all). I must be getting something awfully wrong,
has anyone had more chance trying something similar?

Till


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-01-10 17:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-10 17:08 Implementing rollback channels with Ocamlnet Till Varoquaux

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).