Commits

Alexey Kishkin committed 5bc1cf7

error corrections

Comments (0)

Files changed (2)

          set_i8 buffer extralen;                                   (* 4 *)
          set_i8 buffer 0;                                          (* 5 *) (* RAW data type *)
          set_i16 buffer 0;                                         (*6 7*) (* RESERVED *)
-         set_i32 buffer vllen;                                     (*8 9 10 11*)
+         set_i32 buffer (vllen+keylen+extralen);                   (*8 9 10 11*)
          set_i32 buffer opaque;                                    (*12 13 14 15*)
          set_int64 buffer cas;                                     (*16 17 18 19 20 21 22 23*)
          if extralen > 0 then (Buffer.add_string buffer extras);
          if keylen > 0 then (Buffer.add_string buffer key);
          if vllen > 0 then (Buffer.add_string buffer vl);
          Buffer.contents buffer
-   
+   method printhex pct = 
+       for i=0 to (String.length pct)-1 do
+         Printf.printf " 0x%2x " (Char.code (pct.[i]));
+         if ((i+1) mod  4) == 0 then print_string "\n"
+       done;
+       print_string "\n"
+      
    method decode_header pct =
       try
          let magic = self#magic_code_decode (get_i8 pct 0) in        (* 0 *)
    
    method decode_body pct keylength extralength total_body_length =
       try
-         let extras = (if extralength > 0 then String.sub pct 24 extralength else "") in
-         let key = (if keylength > 0 then String.sub pct (24 + extralength) keylength else "") in
+         let extras = (if extralength > 0 then (String.sub pct 0 extralength) else "") in
+         let key = (if keylength > 0 then String.sub pct (extralength) keylength else "") in
          let valuelength = total_body_length - keylength - extralength in
-         let value = (if valuelength > 0 then String.sub pct (24 + extralength + keylength) valuelength else "") in
+         let value = (if valuelength > 0 then String.sub pct (extralength + keylength) valuelength else "") in
          (key, extras, value)
       with
       | Invalid_argument _ -> raise (Bad_memcache_format "packet too short")
       let extras = Buffer.contents buf in
       let cargo = self#encode_packet Set key extras v 0 0L in
       begin
+        (* self#printhex cargo; *)
          output_string o_channel cargo;
          flush o_channel;
          let (status, key, value, extras, opaque, cas) = self#read_answer in
          let (status, key, value, extras, opaque, cas) = self#read_answer in
          (status, value)
       end
-
+ 
    method get key  =
       let cargo = self#encode_packet Get key "" "" 0 0L in
       begin
 end;;
 
 
+let presult (status,value) = print_endline (match status with
+   | MC_Out_of_memory -> "out_of_memory"
+   | MC_No_error -> ("value "^value)
+   | MC_Key_not_found -> "notfound"
+   | MC_Key_exists -> "key exists"
+   | MC_Value_too_large -> "too large"
+   | MC_Invalid_argument -> "Invalid argument"
+   | MC_Item_not_stored -> "not stored"
+   | MC_Unknown_comamnd -> "unknown command")
+
 let c = new memcache_connector "127.0.0.1" 11211;;
-c#set "walrus" "1963" 0 0;;
+c#set "walrus" "Oi to ne veter to ne veter" 0 0;;
+presult (c#get "walrus");;
+presult (c#get "wax");;
+
+
+    
     method magic_code_decode : int -> magic
     method magic_code_encode : magic -> int
     method operation_encode : operation -> int
+    method printhex : string -> unit
     method read_answer :
       response_status * string * string * string * int * int64
     method response_status_decode : int -> response_status
     method set : string -> string -> int -> int -> response_status * string
   end
+val presult : response_status * string -> unit
+val c : memcache_connector