Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2007-01-10 (17:08)
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=
 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;
  Netbuffer.blit is#window p_in dest dest_pos len;
  p_in <- p_in + len;

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?