Curl wrapper round two

jdrewsen jdrewsen at nospam.com
Wed Jun 22 12:27:12 PDT 2011


Den 22-06-2011 12:08, Dmitry Olshansky skrev:
> On 22.06.2011 14:02, Jonas Drewsen wrote:
>> On 22/06/11 06.11, Jose Armando Garcia wrote:
>>>>> Hi Jonas,
>>>>>
>>>>> Was reading your implementation but I had to context switch. Only go
>>>>> to line 145 :(. I see that you are refcounting by sharing a uint* but
>>>>> what about all the other private fields? What happens if you pass the
>>>>> Curl object around functions and those values are modified?
>>>>>
>>>>> Thanks,
>>>>> -Jose
>>>>
>>>> The refcounting is actually just needed to keep the "handle" alive
>>>> under
>>>> construction of the Curl object using "Curl()". I'm using "Curl()" by
>>>> defining opCall on Curl in order not to have a struct constructor
>>>> with a
>>>> dummy parameter (structs cannot have a default constructor defined).
>>>>
>>>> After that the Curl instance will always be assigned to a member
>>>> variable of
>>>> Http/Ftp classes. Instances of Http/Ftp are not to be copied because
>>>> they
>>>> are used for RAII.
>>>>
>>> Http/Ftp are structs not classes. Let me try to understand this. You
>>> mean to say that the Http and Ftp struct are not to be passed to other
>>> functions? Are you expecting the user to do all their IO in one scope?
>>> This is unnecessarily limiting.
>>>
>>
>> They are structs because they use a Curl instance which in turn uses
>> RAII in order not to leak curl handles. If they were classes it would
>> be easy to leak because you never know when the GC is coming around to
>> call the destructor and release the curl handle.
>>
>> Your can pass Http/Ftp structs to other function either by givin them
>> a reference to a local instance or you could simply do a:
>>
>> auto http = new Http("http://google.com");
>
> I suspect that http is on _heap_ just like class, and it's destructor is
> never called ATM. Even when that's fixed it's still non-deterministic.
> Maybe refcounting? e.g. std.typecons.RefCounted
>
>> passItOn(http);
>>
>> /Jonas

As I replied a minute ago to Jose I'll change it to match the 
std.stdio.File behavior.

/Jonas



More information about the Digitalmars-d mailing list