ares_library_init.3 (4036B)
1 .\" 2 .\" Copyright 1998 by the Massachusetts Institute of Technology. 3 .\" Copyright (C) 2004-2009 by Daniel Stenberg 4 .\" SPDX-License-Identifier: MIT 5 .\" 6 .TH ARES_LIBRARY_INIT 3 "19 May 2009" 7 .SH NAME 8 ares_library_init \- c-ares library initialization 9 .SH SYNOPSIS 10 .nf 11 #include <ares.h> 12 13 int ares_library_init(int \fIflags\fP) 14 15 int ares_library_init_mem(int \fIflags\fP, 16 void *(*\fIamalloc\fP)(size_t), 17 void (*\fIafree\fP)(void *ptr), 18 void (*\fIarealloc\fP)(void *ptr, size_t size)) 19 .fi 20 .SH DESCRIPTION 21 .PP 22 The 23 .B ares_library_init 24 function performs initializations internally required by the c-ares 25 library that must take place before any other function provided by 26 c-ares can be used in a program. 27 .PP 28 This function must be called at least once within the life of a program, 29 before the program actually executes any other c-ares library function. 30 Initializations done by this function remain effective until a number of 31 calls to \fIares_library_cleanup(3)\fP equal to the number of calls to 32 this function are performed. 33 .PP 34 Successive calls to this function do nothing further, only the first 35 call done when c-ares is in an uninitialized state is actually 36 effective. 37 .PP 38 The 39 .I flags 40 parameter is a bit pattern that tells c-ares exactly which features 41 should be initialized, as described below. Set the desired bits by 42 ORing the values together. In normal operation you should specify 43 \fIARES_LIB_INIT_ALL\fP. Don't use any other value unless you are 44 familiar with it and trying to control some internal c-ares feature. 45 .PP 46 The 47 .B ares_library_init_mem 48 function allows the caller to provide memory management functions that the 49 c-ares library will be use instead of \fImalloc(3)\fP, \fIfree(3)\fP and 50 \fIrealloc(3)\fP. 51 .PP 52 .B This function is not thread safe. 53 You have to call it once the program has started, but this call must be done 54 before the program starts any other thread. This is required to avoid 55 potential race conditions in library initialization, and also due to the fact 56 that \fIares_library_init(3)\fP might call functions from other libraries that 57 are thread unsafe, and could conflict with any other thread that is already 58 using these other libraries. 59 .PP 60 On Windows platforms, the library user should ensure that \fIWSAStartup()\fP 61 is called before the c-ares library is initialized and used. 62 .PP 63 Win32/64 application DLLs shall not call \fIares_library_init(3)\fP from the 64 DllMain function. Doing so will produce deadlocks and other problems. 65 .SH FLAGS 66 .TP 5 67 .B ARES_LIB_INIT_ALL 68 Initialize everything possible. This sets all known bits. 69 .TP 70 .B ARES_LIB_INIT_WIN32 71 Initialize Win32/64 specific libraries. As of c-ares 1.19.0, this is ignored 72 as there are no currently dynamically loaded libraries. 73 .TP 74 .B ARES_LIB_INIT_NONE 75 Initialize nothing extra. This sets no bit. 76 .SH RETURN VALUE 77 Upon successful completion, \fIares_library_init(3)\fP returns 0. Otherwise, 78 a non-zero error number is returned to indicate the error. Except for 79 \fIares_strerror(3)\fP, you shall not call any other c-ares function upon 80 \fIares_library_init(3)\fP failure. 81 .SH AVAILABILITY 82 This function was first introduced in c-ares version 1.7.0 along with the 83 definition of preprocessor symbol \fICARES_HAVE_ARES_LIBRARY_INIT\fP as an 84 indication of the availability of this function. Its recursive behavior, which 85 requires a matching number of calls to \fIares_library_cleanup(3)\fP in order 86 to deinitialize the library, is present since c-ares version 1.10.0. Earlier 87 versions would deinitialize the library on the first call to 88 \fIares_library_cleanup(3)\fP. 89 .PP 90 Since the introduction of this function it is absolutely mandatory to 91 call it for any Win32/64 program using c-ares. 92 .PP 93 Non-Win32/64 systems can still use c-ares version 1.7.0 without calling 94 \fIares_library_init(3)\fP due to the fact that \fIcurrently\fP it is nearly 95 a do-nothing function on non-Win32/64 platforms at this point. 96 .SH SEE ALSO 97 .BR ares_library_cleanup (3), 98 .BR ares_strerror (3)