Merge pull request #1389 from Unidata/curlcleanup.dmh

Centralize calls to curl_global_init and curl_global_cleanup
This commit is contained in:
Ward Fisher 2019-05-03 15:28:57 -06:00 committed by GitHub
commit 3e67d4b8a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 31 deletions

View File

@ -200,7 +200,6 @@ NCD2_initialize(void)
int
NCD2_finalize(void)
{
curl_global_cleanup();
return NC_NOERR;
}

View File

@ -61,7 +61,6 @@ NCD4_initialize(void)
int
NCD4_finalize(void)
{
curl_global_cleanup();
return THROW(NC_NOERR);
}
@ -793,13 +792,6 @@ static int
globalinit(void)
{
int stat = NC_NOERR;
{
CURLcode cstat = curl_global_init(CURL_GLOBAL_DEFAULT);
if(cstat != CURLE_OK)
fprintf(stderr,"curl_global_init failed!\n");
}
return stat;
}

View File

@ -22,6 +22,9 @@ See LICENSE.txt for license information.
#define getcwd _getcwd
#endif
#if defined(ENABLE_BYTERANGE) || defined(ENABLE_DAP) || defined(ENABLE_DAP4)
#include <curl/curl.h>
#endif
/* Define vectors of zeros and ones for use with various nc_get_varX function*/
const size_t NC_coord_zero[NC_MAX_VAR_DIMS];
@ -122,6 +125,14 @@ NCDISPATCH_initialize(void)
/* Compute type alignments */
NC_compute_alignments();
/* Initialize curl if it is being used */
#if defined(ENABLE_BYTERANGE) || defined(ENABLE_DAP) || defined(ENABLE_DAP4)
{
CURLcode cstat = curl_global_init(CURL_GLOBAL_ALL);
if(cstat != CURLE_OK)
status = NC_ECURL;
}
#endif
return status;
}
@ -130,6 +141,9 @@ NCDISPATCH_finalize(void)
{
int status = NC_NOERR;
ncrc_freeglobalstate();
#if defined(ENABLE_BYTERANGE) || defined(ENABLE_DAP) || defined(ENABLE_DAP4)
curl_global_cleanup();
#endif
return status;
}

View File

@ -125,7 +125,7 @@ NC_HDF5_initialize(void)
#ifdef ENABLE_BYTERANGE
(void)H5FD_http_init();
#endif
#endif
return NC4_provenance_init();
}

View File

@ -21,6 +21,7 @@
#include <unistd.h>
#endif
#include "nc3internal.h"
#include "ncwinpath.h"
#undef DEBUG
@ -242,17 +243,13 @@ mmapio_create(const char* path, int ioflags,
oflags |= (O_CREAT|O_TRUNC);
if(fIsSet(ioflags,NC_NOCLOBBER))
oflags |= O_EXCL;
#ifdef vms
fd = open(path, oflags, 0, "ctx=stm");
#else
fd = open(path, oflags, OPENMODE);
#endif
fd = NCopen3(path, oflags, OPENMODE);
if(fd < 0) {status = errno; goto unwind_open;}
mmapio->mapfd = fd;
{ /* Cause the output file to have enough allocated space */
lseek(fd,mmapio->alloc-1,SEEK_SET); /* cause file to appear */
write(fd,"",mmapio->alloc);
write(fd,"",1);
lseek(fd,0,SEEK_SET); /* rewind */
}
mmapio->memory = (char*)mmap(NULL,mmapio->alloc,
@ -337,11 +334,7 @@ mmapio_open(const char* path,
fSet(oflags, O_BINARY);
#endif
oflags |= O_EXCL;
#ifdef vms
fd = open(path, oflags, 0, "ctx=stm");
#else
fd = open(path, oflags, OPENMODE);
#endif
fd = NCopen3(path, oflags, OPENMODE);
if(fd < 0) {status = errno; goto unwind_open;}
/* get current filesize = max(|file|,initialize)*/
@ -420,7 +413,6 @@ static int
mmapio_pad_length(ncio* nciop, off_t length)
{
NCMMAPIO* mmapio;
int persist = 0;
if(nciop == NULL || nciop->pvt == NULL) return NC_EINVAL;
mmapio = (NCMMAPIO*)nciop->pvt;
@ -431,9 +423,6 @@ mmapio_pad_length(ncio* nciop, off_t length)
if(mmapio->locked > 0)
return NC_EDISKLESS;
if(mmapio->mapfd >= 0)
persist = 1;
if(length > mmapio->alloc) {
/* Realloc the allocated memory to a multiple of the pagesize*/
off_t newsize = length;
@ -455,8 +444,9 @@ mmapio_pad_length(ncio* nciop, off_t length)
newmem = (char*)mremap(mmapio->memory,mmapio->alloc,newsize,MREMAP_MAYMOVE);
if(newmem == NULL) return NC_ENOMEM;
#else
/* note: mmapio->mapfd >= 0 => persist */
newmem = (char*)mmap(NULL,newsize,
persist?(PROT_READ|PROT_WRITE):(PROT_READ),
mmpio->mapfd >= 0?(PROT_READ|PROT_WRITE):(PROT_READ),
MAP_SHARED,
mmapio->mapfd,0);
if(newmem == NULL) return NC_ENOMEM;

View File

@ -64,7 +64,6 @@ OCerror
ocinternalinitialize(void)
{
int stat = OC_NOERR;
CURLcode cstat = CURLE_OK;
if(ocinitialized) return OC_NOERR;
ocinitialized = 1;
@ -79,10 +78,6 @@ ocinternalinitialize(void)
}
#endif
cstat = curl_global_init(CURL_GLOBAL_ALL);
if(cstat != CURLE_OK)
fprintf(stderr,"curl_global_init failed!\n");
/* Compute some xdr related flags */
xxdr_init();