X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Focaml-http%2Fexamples%2Fdamned_recursion.ml;h=c7fbe846f3b2af04b3c06988303e31cc8ebd38f2;hb=8c838424df850f6e139733b32c3e1680246a4184;hp=0280b3f1c5a0795d9b98359813b97f502529dd4b;hpb=e2103d86692f0782eca040d7fdf9c1080fa229fc;p=helm.git diff --git a/helm/DEVEL/ocaml-http/examples/damned_recursion.ml b/helm/DEVEL/ocaml-http/examples/damned_recursion.ml index 0280b3f1c..c7fbe846f 100644 --- a/helm/DEVEL/ocaml-http/examples/damned_recursion.ml +++ b/helm/DEVEL/ocaml-http/examples/damned_recursion.ml @@ -22,28 +22,23 @@ open Http_types;; open Printf;; -(* -let wget url = - prerr_endline (sprintf "DEBUG: wgetting url '%s'" url); - Http_client.Convenience.http_get url -in -*) let wget addr port path = - let rec wget' inchan data = - try - wget' inchan (data ^ input_line inchan) - with End_of_file -> - data + let rec wget' inchan buf = + Buffer.add_string buf (input_line inchan ^ "\n"); + wget' inchan buf in prerr_endline (sprintf "DEBUG: wgetting url '%s:%d%s'" addr port path); let sockaddr = Unix.ADDR_INET (Unix.inet_addr_of_string addr, port) in let suck = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in Unix.connect suck sockaddr; let outchan = Unix.out_channel_of_descr suck in - output_string outchan (sprintf "GET %s HTTP/1.0\r\n" path); + output_string outchan (sprintf "GET %s HTTP/1.0\r\n\r\n" path); flush outchan; let inchan = Unix.in_channel_of_descr suck in - wget' inchan "" + let buf = Buffer.create 1023 in + try + wget' inchan buf + with End_of_file -> Buffer.contents buf in let callback (req: request) outchan = let i = int_of_string (req#param "x") in @@ -53,12 +48,11 @@ let callback (req: request) outchan = | x when x>0 -> let data = wget "127.0.0.1" 9999 (sprintf "/foo?x=%d" (x-1)) -(* wget (sprintf "http://localhost:9999/foo?x=%d" (x-1)) *) -(* wget "http://localhost:80/index.html" *) +(* wget "127.0.0.1" 80 "/index.html" *) in output_string outchan (sprintf "%s %d" data x) | _ -> assert false in -Http_client.Convenience.http_trials := 1; -(* Http_daemon.start' ~port:9999 ~mode:`Thread callback *) -Http_daemon.start' ~port:9999 ~mode:`Fork callback +let mode = `Thread in +Http_daemon.start' ~port:9999 ~mode callback +