Version française
Home     About     Download     Resources     Contact us    
Browse thread
Implementing rollback channels with Ocamlnet
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Till Varoquaux <till.varoquaux@g...>
Subject: Implementing rollback channels with Ocamlnet
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