@@ -10,7 +10,7 @@ const checkCode = curl.checkCode;
1010const Writer = std .io .Writer ;
1111
1212fn newEasy (writer : * Writer , url : [:0 ]const u8 ) ! Easy {
13- const easy = try Easy .init (.{});
13+ var easy = try Easy .init (.{});
1414 try easy .setUrl (url );
1515 try easy .setWriter (writer );
1616 // CURLOPT_PRIVATE allows us to store a pointer to the ctx in the easy handle
@@ -25,16 +25,23 @@ pub fn main() !void {
2525 defer if (gpa .deinit () != .ok ) @panic ("leak" );
2626 const allocator = gpa .allocator ();
2727
28- const multi = try Multi .init ();
28+ var diagnostics : Multi.Diagnostics = .{};
29+
30+ const multi = try Multi .init (& diagnostics );
2931 defer multi .deinit ();
3032
3133 var wtr1 = std .Io .Writer .Allocating .init (allocator );
3234 defer wtr1 .deinit ();
3335 var wtr2 = std .Io .Writer .Allocating .init (allocator );
3436 defer wtr2 .deinit ();
3537
36- try multi .addHandle (try newEasy (& wtr1 .writer , "http://edgebin.liujiacai.net/headers" ));
37- try multi .addHandle (try newEasy (& wtr2 .writer , "http://edgebin.liujiacai.net/ip" ));
38+ var easy1 = try newEasy (& wtr1 .writer , "http://edgebin.liujiacai.net/headers" );
39+ defer easy1 .deinit ();
40+ var easy2 = try newEasy (& wtr2 .writer , "http://edgebin.liujiacai.net/ip" );
41+ defer easy2 .deinit ();
42+
43+ try multi .addHandle (& easy1 );
44+ try multi .addHandle (& easy2 );
3845
3946 var keep_running = true ;
4047 while (keep_running ) {
@@ -60,16 +67,16 @@ pub fn main() !void {
6067 }
6168
6269 // check that the request was successful
63- try checkCode (info .msg .data .result );
70+ try checkCode (info .msg .data .result , & diagnostics );
6471
6572 // Read the HTTP status code
6673 var status_code : c_long = 0 ;
67- try checkCode (c .curl_easy_getinfo (easy_handle , c .CURLINFO_RESPONSE_CODE , & status_code ));
74+ try checkCode (c .curl_easy_getinfo (easy_handle , c .CURLINFO_RESPONSE_CODE , & status_code ), & diagnostics );
6875 std .debug .print ("Response Code: {any}\n " , .{status_code });
6976
7077 // Get the private data (buffer) associated with this handle
7178 var private_data : ? * anyopaque = null ;
72- try checkCode (c .curl_easy_getinfo (easy_handle , c .CURLINFO_PRIVATE , & private_data ));
79+ try checkCode (c .curl_easy_getinfo (easy_handle , c .CURLINFO_PRIVATE , & private_data ), & diagnostics );
7380 const writer : * Writer = @ptrCast (@alignCast (private_data .? ));
7481
7582 std .debug .print ("Response body: {s}\n " , .{writer .buffered ()});
0 commit comments