www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Curl namelookup_time

reply Andre Pany <andre s-e-a-p.de> writes:
Hi,

I try to get some cUrl measurements like name lookup time.

pragma(lib, "curl");
import std.stdio, std.net.curl, etc.c.curl;

void main()
{
	Curl curl;
	curl.initialize();
	curl.set(CurlOption.url, "https://www.google.com");
	curl.perform();
	
	double d;
	curl_easy_getinfo(&curl, CurlInfo.namelookup_time, &d);
	writeln(d);
}

While the cUrl console application return values like "0,015",
this coding returns values like "9.71874e-311".

Where is the bug?

Kind regards
André
Nov 23 2016
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 23 November 2016 at 08:24:46 UTC, Andre Pany wrote:
 	Curl curl;
 	curl_easy_getinfo(&curl, CurlInfo.namelookup_time, &d);
curl_easy_getinfo expects the C handle, CURL*, but you are passing it the D struct, Curl. I don't understand why this even compiles, it should give an invalid argument type error.... let me guess, it has `alias void CURL`... hey look, there it is: http://dpldocs.info/experimental-docs/source/etc.c.curl.d.html#L110 thanks, zero typechecks. It really should be an opaque struct. Lemme guess too, it was a typedef in C. https://github.com/curl/curl/blob/master/include/curl/curl.h#L102 gee, typedef and alias aren't the same! This is a bug. A REALLY common bug. Anyway, as to your specific instance, the D Curl struct has no public function to return the underlying C handle. To use the C functions, you'll have to create them using C functions too.
Nov 23 2016
parent Andre Pany <andre s-e-a-p.de> writes:
On Wednesday, 23 November 2016 at 13:59:29 UTC, Adam D. Ruppe 
wrote:
 On Wednesday, 23 November 2016 at 08:24:46 UTC, Andre Pany 
 wrote:
 [...]
curl_easy_getinfo expects the C handle, CURL*, but you are passing it the D struct, Curl. [...]
Thank you Adam. I will create a bug report and also an enhancement request. Getting the the time values is quite cumbersome:) Kind regards André
Nov 23 2016