lib/curl: use a cached instance of `Curl` in `Sys`
authorAlexis Laferrière <alexis.laf@xymus.net>
Sun, 7 Jun 2015 12:24:33 +0000 (08:24 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Sun, 7 Jun 2015 19:41:46 +0000 (15:41 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/curl/curl.nit

index b77b0f1..83d8efc 100644 (file)
@@ -19,11 +19,20 @@ module curl
 
 import native_curl
 
+redef class Sys
+       # Shared Curl library handle
+       #
+       # Usually, you do not have to use this attribute, it instancied by `CurlHTTPRequest` and `CurlMail`.
+       # But in some cases you may want to finalize it to free some small resources.
+       # However, if Curl services are needed once again, this attribute must be manually set.
+       var curl: Curl = new Curl is lazy, writable
+end
+
 # Curl library handle, it is initialized and released with this class
 class Curl
        super FinalizableOnce
 
-       protected var native = new NativeCurl.easy_init
+       private var native = new NativeCurl.easy_init
 
        # Check for correct initialization
        fun is_ok: Bool do return self.native.is_init
@@ -34,7 +43,7 @@ end
 # CURL Request
 class CurlRequest
 
-       private var curl: Curl
+       private var curl: Curl = sys.curl
 
        # Shall this request be verbose?
        var verbose: Bool = false is writable