/[mldonkey]/mldonkey/src/utils/lib/store.ml
ViewVC logotype

Diff of /mldonkey/src/utils/lib/store.ml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by mldonkey, Thu Jul 29 10:25:34 2004 UTC revision 1.5 by spiralvoice, Thu Jul 7 00:25:46 2005 UTC
# Line 63  let rec iter_write fd s pos len = Line 63  let rec iter_write fd s pos len =
63  let really_write fd pos s =  let really_write fd pos s =
64    let len = String.length s in    let len = String.length s in
65    if verbose then begin    if verbose then begin
66        lprintf "write %d %d" pos len; lprint_newline ();        lprintf_nl "write %d %d" pos len;
67      end;      end;
68    ignore (seek64 fd  (Int64.of_int pos) Unix.SEEK_SET);    ignore (seek64 fd  (Int64.of_int pos) Unix.SEEK_SET);
69    iter_write fd s 0 len    iter_write fd s 0 len
# Line 75  let rec iter_read fd s pos len = Line 75  let rec iter_read fd s pos len =
75        
76  let really_read fd pos s len =  let really_read fd pos s len =
77    if verbose then begin    if verbose then begin
78        lprintf "read %d %d" pos len; lprint_newline ();        lprintf_nl "read %d %d" pos len;
79      end;      end;
80    ignore (seek64 fd  (Int64.of_int pos) Unix.SEEK_SET);    ignore (seek64 fd  (Int64.of_int pos) Unix.SEEK_SET);
81    iter_read fd s 0 len    iter_read fd s 0 len
# Line 108  let file_store file str = Line 108  let file_store file str =
108        let new_weak = Weak.create new_size in        let new_weak = Weak.create new_size in
109        (try Array.blit file.file_all_pos 0 new_tab 0 pos        (try Array.blit file.file_all_pos 0 new_tab 0 pos
110          with e ->          with e ->
111              lprintf "exc pos %d" pos; lprint_newline ();              lprintf_nl "exc pos %d" pos;
112              raise e);              raise e);
113        Weak.blit file.file_cache 0 new_weak 0 pos;        Weak.blit file.file_cache 0 new_weak 0 pos;
114        for i = pos to new_size - 1 do new_tab.(i) <- i+1; done;        for i = pos to new_size - 1 do new_tab.(i) <- i+1; done;
# Line 170  let save t doc v attr = Line 170  let save t doc v attr =
170    in    in
171    let pos = file_store file str in    let pos = file_store file str in
172    if verbose then begin    if verbose then begin
173        lprintf "REALLY WRITE TO %d POS %d LEN %d"        lprintf_nl "REALLY WRITE TO %d POS %d LEN %d"
174          chunk_size pos len;          chunk_size pos len;
       lprint_newline ();  
175      end;      end;
176    Weak.set file.file_cache pos (Some v);    Weak.set file.file_cache pos (Some v);
177    let comb = combine pos chunk_size attr in    let comb = combine pos chunk_size attr in
# Line 185  let add t v = Line 184  let add t v =
184        let new_size = (len_all_doc + 10) * 2 in        let new_size = (len_all_doc + 10) * 2 in
185        let new_tab = Array.create new_size 0 in        let new_tab = Array.create new_size 0 in
186        (try Array.blit t.store_all_doc 0 new_tab 0 doc        (try Array.blit t.store_all_doc 0 new_tab 0 doc
187          with e -> lprintf "Error in blit %d/%d" doc len_all_doc; lprint_newline ();          with e -> lprintf_nl "Error in blit %d/%d" doc len_all_doc;
188              raise e)              raise e)
189            ;            ;
190        for i = doc to new_size - 1 do new_tab.(i) <- i+1; done;        for i = doc to new_size - 1 do new_tab.(i) <- i+1; done;
# Line 201  let get t doc = Line 200  let get t doc =
200    let file = List.assoc chunk_size t.store_files in    let file = List.assoc chunk_size t.store_files in
201    let v =  try Weak.get file.file_cache pos    let v =  try Weak.get file.file_cache pos
202      with e ->      with e ->
203          lprintf "Exception %s for doc at pos %d (doc %d, combine %d)" (Printexc2.to_string e)          lprintf_nl "Exception %s for doc at pos %d (doc %d, combine %d)" (Printexc2.to_string e)
204          pos doc combine; lprint_newline ();          pos doc combine;
205          raise e          raise e
206        in        in
207    match v with    match v with
208      None ->      None ->
209        let len = file.file_entry_size in        let len = file.file_entry_size in
210        if verbose then begin        if verbose then begin
211            lprintf "REALLY READ FROM %d POS %d LEN %d"            lprintf_nl "REALLY READ FROM %d POS %d LEN %d"
212              chunk_size pos len;              chunk_size pos len;
           lprint_newline ();  
213          end;          end;
214        let str = file_retrieve file pos in        let str = file_retrieve file pos in
215        begin        begin
216          try          try
217            Marshal.from_string str 0            Marshal.from_string str 0
218          with e ->          with e ->
219              lprintf "Marshal.from_string error";              lprintf_nl "Marshal.from_string error";
220              lprint_newline (); raise e              raise e
221        end        end
222    | Some v ->    | Some v ->
223        if verbose then begin        if verbose then
224            lprintf "Reply found in cache"; lprint_newline ();            lprintf_nl "Reply found in cache";
         end;  
225        v        v
226    
227                
# Line 275  let stats t = Line 272  let stats t =
272          | Some _ -> incr counter;          | Some _ -> incr counter;
273        done;        done;
274    ) t.store_files;    ) t.store_files;
   !counter, Array.length t.store_all_doc  
275      !counter, Array.length t.store_all_doc

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26