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, -JoseThe 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
