From 05b386655dd8c3e8a4466504cbf862fcc3fb4a7a Mon Sep 17 00:00:00 2001 From: ygrek Date: Wed, 19 Mar 2014 01:44:29 +0800 Subject: [PATCH] Curl_lwt: actually set error_buffer when finished --- .gitignore | 1 + curl-helper.c | 8 +++++++- examples/Makefile.in | 8 ++++---- examples/test_lwt_unit.ml | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 examples/test_lwt_unit.ml diff --git a/.gitignore b/.gitignore index 5489ec0..f46c429 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,5 @@ examples/ocurl examples/ocurl_test_threads examples/test_cb_exn examples/test_lwt +examples/test_lwt_unit /doc diff --git a/curl-helper.c b/curl-helper.c index 54ca9d1..6d833f7 100644 --- a/curl-helper.c +++ b/curl-helper.c @@ -6409,6 +6409,7 @@ CAMLprim value caml_curlm_remove_finished(value v_multi) CURL* handle; CURLM* multi_handle; CURLcode result; + Connection* conn = NULL; multi_handle = CURLM_val(v_multi); @@ -6422,8 +6423,13 @@ CAMLprim value caml_curlm_remove_finished(value v_multi) } else { + conn = findConnection(handle); + if (conn->errorBuffer != NULL) + { + Store_field(Field(conn->ocamlValues, OcamlErrorBuffer), 0, caml_copy_string(conn->errorBuffer)); + } /* NB: same handle, but different block */ - v_easy = caml_curl_alloc(findConnection(handle)); + v_easy = caml_curl_alloc(conn); v_tuple = caml_alloc(2, 0); Store_field(v_tuple,0,v_easy); Store_field(v_tuple,1,Val_int(result)); /* CURLcode */ diff --git a/examples/Makefile.in b/examples/Makefile.in index 7f90424..3ca7bb8 100644 --- a/examples/Makefile.in +++ b/examples/Makefile.in @@ -18,22 +18,22 @@ OCURLOPTLIB = curl.cmxa unix.cmxa threads.cmxa TARGETS = ocurl oput ominimal ossl ocurl_test_threads opar test_cb_exn ifneq (@OCAML_PKG_lwt@,no) -TARGETS += test_lwt +TARGETS += test_lwt test_lwt_unit endif ifeq (@OCAMLBEST@,opt) TARGETS += ocurl.opt oput.opt ominimal.opt ossl.opt ocurl_test_threads.opt opar.opt test_cb_exn.opt ifneq (@OCAML_PKG_lwt@,no) -TARGETS += test_lwt.opt +TARGETS += test_lwt.opt test_lwt_unit.opt endif endif all: $(TARGETS) -test_lwt: test_lwt.ml +test_lwt%: test_lwt%.ml $(FINDLIB) c -custom -linkpkg -package lwt.unix $(LFLAGS) curl.cma curl_lwt.cmo $< -o $@ -test_lwt.opt: test_lwt.ml +test_lwt%.opt: test_lwt%.ml $(FINDLIB) opt -linkpkg -package lwt.unix $(LFLAGS) curl.cmxa curl_lwt.cmx $< -o $@ %: %.cmo diff --git a/examples/test_lwt_unit.ml b/examples/test_lwt_unit.ml new file mode 100644 index 0000000..e2df03f --- /dev/null +++ b/examples/test_lwt_unit.ml @@ -0,0 +1,35 @@ +(* Copyright (c) 2014, Thomas Leonard, *) + +open Curl +open Printf + +let verbose = false + +let (|>) x f = f x +let printfn fmt = ksprintf print_endline fmt + +let setup buf = + let h = init () in + set_url h "http://localhost:1/missing.png"; + set_errorbuffer h buf; + h + +let () = + let buf1 = ref "" in + let h = setup buf1 in + (* easy *) + let () = try + perform h + with CurlException (code,_,_) -> + if verbose then printfn "Sync errors: %s <%s>" (strerror code) !buf1 + in + (* lwt *) + let buf2 = ref "" in + let h = setup buf2 in + let code = Curl_lwt.perform h |> Lwt_main.run in + if verbose then printfn "Lwt errors: %s <%s>" (strerror code) !buf2; + + if buf1 <> buf2 then + (printfn "FAILED: %S <> %S" !buf1 !buf2; exit 1) + else + (printfn "OK"; exit 0) -- 2.11.4.GIT