2 * ----------------------------------------------------------------------
8 { s_channel : in_channel;
9 s_maxlength : int option;
11 mutable s_current_length : int;
12 mutable s_at_eos : bool;
13 mutable s_win_pos : int;
14 mutable s_win_len : int;
15 s_netbuf : Netbuffer.t;
22 print_string ("*** NETSTREAM DUMP " ^ text ^ "\n");
23 Printf.printf "current_length=%d at_eos=%b win_pos=%d win_len=%d\n"
24 s.s_current_length s.s_at_eos s.s_win_pos s.s_win_len;
25 Printf.printf "netbuffer_length=%d netbuffer_size=%d\n"
26 (Netbuffer.length s.s_netbuf)
27 (String.length(Netbuffer.unsafe_buffer s.s_netbuf));
28 Printf.printf "netbuffer=\"%s\"\n"
29 (String.escaped(Netbuffer.contents s.s_netbuf));
30 print_string "*** ---------------\n";
35 let want_another_block s =
36 if not s.s_at_eos then begin
37 (* How much are we allowed to read? *)
39 match s.s_maxlength with
41 | Some k -> min (k - s.s_current_length) s.s_blocksize
44 let rec read_block k =
47 input s.s_channel s.s_iobuf k (m - k) in
56 let n = read_block 0 in
57 (* If n < blocksize, EOS is reached. *)
58 Netbuffer.add_sub_string s.s_netbuf s.s_iobuf 0 n;
59 s.s_win_len <- s.s_win_len + n;
60 s.s_current_length <- s.s_current_length + n;
61 s.s_at_eos <- n < s.s_blocksize;
63 (* dump s "After appending block"; *)
69 while not s.s_at_eos && s.s_win_len < n do
76 want s (s.s_blocksize + s.s_blocksize)
81 Netbuffer.delete s.s_netbuf 0 n;
82 s.s_win_pos <- s.s_win_pos + n;
83 s.s_win_len <- s.s_win_len - n;
85 (* dump s "After move"; *)
89 let create_from_channel ch maxlength blocksize =
92 s_maxlength = maxlength;
93 s_blocksize = blocksize;
98 s_netbuf = Netbuffer.create (2*blocksize);
99 s_iobuf = String.create blocksize;
107 let create_from_string str =
108 let l = String.length str in
112 s_current_length = l;
117 ( let nb = Netbuffer.create l in
118 Netbuffer.add_string nb str;
126 let block_size s = s.s_blocksize;;
128 let current_length s = s.s_current_length;;
130 let at_eos s = s.s_at_eos;;
132 let window_position s = s.s_win_pos;;
134 let window_length s = s.s_win_len;;
136 let window s = s.s_netbuf;;
140 "<NETSTREAM window:%d/%d total_length:%d eof=%b>"
148 (* ======================================================================
152 * Revision 1.1 2000/11/17 09:57:27 lpadovan
155 * Revision 1.2 2000/06/24 20:20:33 gerd
156 * Added the toploop printer.
158 * Revision 1.1 2000/04/15 13:07:48 gerd