Curl wrapper round two

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


Den 22-06-2011 17:34, Jose Armando Garcia skrev:
> Em 22/06/2011, às 07:02, Jonas Drewsen <jdrewsen at nospam.com> escreveu:
>
>> 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");
>> passItOn(http);
>>
>> /Jonas
>
> Passing refs around doesn't work if the function wants to store it on
> the heap for later.
>
> Have you taken a look at how std.stdio.File and std.typecons.RefCounted
> do reference counting?

I think I'll change it to match std.stdio.File in the name of consistency.

Thanks
/Jonas




More information about the Digitalmars-d mailing list