2 Test threads and GC interaction in bindings
4 ocamlopt -thread -c -I .. ocurl_test_threads.ml -o ocurl_test_threads.cmx
5 ocamlopt -thread unix.cmxa threads.cmxa -I .. -ccopt -L.. curl.cmxa ocurl_test_threads.cmx -o ocurl_test_threads
8 let read_file connection path
=
9 let id = (Thread.id (Thread.self
())) in
10 Printf.printf
"%u read_file %s...\n%!" id path
;
11 let received_size = ref 0L in
12 let writefunction buffer
=
13 let buffer_size = String.length buffer
in
14 Printf.printf
"W(%d)%!" buffer_size;
15 received_size := Int64.add
!received_size (Int64.of_int
buffer_size);
18 Curl.set_httpget connection
true;
19 Curl.set_url connection path
;
20 Curl.set_writefunction connection
writefunction;
21 Curl.perform connection
;
22 Printf.printf
"%u done \n%!" id;
23 match Curl.get_responsecode connection
with
27 failwith
(Printf.sprintf
"read_file %d" code
)
30 Curl.global_init
Curl.CURLINIT_GLOBALALL
;
32 let connection = Curl.init
() in
33 let path = if Array.length
Sys.argv
> 1 then Sys.argv
.(1) else "http://localhost:8080/files/test.tar.gz" in
35 ignore
(read_file connection path)
38 let a = Array.init
20 (fun _
-> Thread.create
f ()) in
39 Array.iter
Thread.join
a