From dde308108501ba1e7ebf817b5e5eaa61fa1031b6 Mon Sep 17 00:00:00 2001 From: Steve Holme Date: Sun, 2 Feb 2014 15:28:25 +0000 Subject: tool_operate: Introduced operate_init() function --- src/tool_operate.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'src/tool_operate.c') diff --git a/src/tool_operate.c b/src/tool_operate.c index da76f55f4..a4e8069c8 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -184,6 +184,17 @@ static curl_off_t VmsSpecialSize(const char * name, } #endif /* __VMS */ +static CURLcode operate_init(struct Configurable *config) +{ + /* Get a curl handle to use for all forthcoming curl transfers */ + config->easy = curl_easy_init(); + if(!config->easy) { + helpf(config->errors, "error initializing curl easy handle\n"); + return CURLE_FAILED_INIT; + } + + return CURLE_OK; +} static int operate_do(struct Configurable *config, int argc, argv_item_t argv[]) { @@ -196,7 +207,7 @@ static int operate_do(struct Configurable *config, int argc, argv_item_t argv[]) metalinkfile *mlfile_last = NULL; - CURL *curl = NULL; + CURL *curl = config->easy; char *httpgetfields = NULL; int res = 0; @@ -212,14 +223,6 @@ static int operate_do(struct Configurable *config, int argc, argv_item_t argv[]) heads.stream = stdout; heads.config = config; - /* Get a curl handle to use for all forthcoming curl transfers */ - curl = curl_easy_init(); - if(!curl) { - helpf(config->errors, "error initializing curl easy handle\n"); - return CURLE_FAILED_INIT; - } - config->easy = curl; - /* ** Beyond this point no return'ing from this function allowed. ** Jump to label 'quit_curl' in order to abandon this function @@ -1842,5 +1845,13 @@ static int operate_do(struct Configurable *config, int argc, argv_item_t argv[]) int operate(struct Configurable *config, int argc, argv_item_t argv[]) { + int result = 0; + + /* Initialize the easy interface */ + result = operate_init(config); + if(result) + return result; + + /* Perform the main operation */ return operate_do(config, argc, argv); } -- cgit v1.2.3