Blame ares_library_init.3

Packit 514978
.\"
Packit 514978
.\" Copyright 1998 by the Massachusetts Institute of Technology.
Packit 514978
.\" Copyright (C) 2004-2009 by Daniel Stenberg
Packit 514978
.\"
Packit 514978
.\" Permission to use, copy, modify, and distribute this
Packit 514978
.\" software and its documentation for any purpose and without
Packit 514978
.\" fee is hereby granted, provided that the above copyright
Packit 514978
.\" notice appear in all copies and that both that copyright
Packit 514978
.\" notice and this permission notice appear in supporting
Packit 514978
.\" documentation, and that the name of M.I.T. not be used in
Packit 514978
.\" advertising or publicity pertaining to distribution of the
Packit 514978
.\" software without specific, written prior permission.
Packit 514978
.\" M.I.T. makes no representations about the suitability of
Packit 514978
.\" this software for any purpose.  It is provided "as is"
Packit 514978
.\" without express or implied warranty.
Packit 514978
.\"
Packit 514978
.TH ARES_LIBRARY_INIT 3 "19 May 2009"
Packit 514978
.SH NAME
Packit 514978
ares_library_init \- c-ares library initialization
Packit 514978
.SH SYNOPSIS
Packit 514978
.nf
Packit 514978
#include <ares.h>
Packit 514978
Packit 514978
int ares_library_init(int \fIflags\fP)
Packit 514978
Packit 514978
int ares_library_init_mem(int \fIflags\fP,
Packit 514978
                          void *(*\fIamalloc\fP)(size_t),
Packit 514978
                          void (*\fIafree\fP)(void *ptr),
Packit 514978
                          void (*\fIarealloc\fP)(void *ptr, size_t size))
Packit 514978
.fi
Packit 514978
.SH DESCRIPTION
Packit 514978
.PP
Packit 514978
The
Packit 514978
.B ares_library_init
Packit 514978
function performs initializations internally required by the c-ares
Packit 514978
library that must take place before any other function provided by
Packit 514978
c-ares can be used in a program.
Packit 514978
.PP
Packit 514978
This function must be called at least once within the life of a program,
Packit 514978
before the program actually executes any other c-ares library function.
Packit 514978
Initializations done by this function remain effective until a number of
Packit 514978
calls to \fIares_library_cleanup(3)\fP equal to the number of calls to
Packit 514978
this function are performed.
Packit 514978
.PP
Packit 514978
Successive calls to this function do nothing further, only the first
Packit 514978
call done when c-ares is in an uninitialized state is actually
Packit 514978
effective.
Packit 514978
.PP
Packit 514978
The
Packit 514978
.I flags
Packit 514978
parameter is a bit pattern that tells c-ares exactly which features
Packit 514978
should be initialized, as described below. Set the desired bits by
Packit 514978
ORing the values together. In normal operation you should specify
Packit 514978
\fIARES_LIB_INIT_ALL\fP. Don't use any other value unless you are
Packit 514978
familiar with it and trying to control some internal c-ares feature.
Packit 514978
.PP
Packit 514978
The
Packit 514978
.B ares_library_init_mem
Packit 514978
function allows the caller to provide memory management functions that the
Packit 514978
c-ares library will be use instead of \fImalloc(3)\fP, \fIfree(3)\fP and
Packit 514978
\fIrealloc(3)\fP.
Packit 514978
.PP
Packit 514978
.B This function is not thread safe.
Packit 514978
You have to call it once the program has started, but this call must be done
Packit 514978
before the program starts any other thread. This is required to avoid
Packit 514978
potential race conditions in library initialization, and also due to the fact
Packit 514978
that \fIares_library_init(3)\fP might call functions from other libraries that
Packit 514978
are thread unsafe, and could conflict with any other thread that is already
Packit 514978
using these other libraries.
Packit 514978
.PP
Packit 514978
Win32/64 application DLLs shall not call \fIares_library_init(3)\fP from the
Packit 514978
DllMain function. Doing so will produce deadlocks and other problems.
Packit 514978
.SH FLAGS
Packit 514978
.TP 5
Packit 514978
.B ARES_LIB_INIT_ALL
Packit 514978
Initialize everything possible. This sets all known bits.
Packit 514978
.TP
Packit 514978
.B ARES_LIB_INIT_WIN32
Packit 514978
Initialize Win32/64 specific libraries.
Packit 514978
.TP
Packit 514978
.B ARES_LIB_INIT_NONE
Packit 514978
Initialize nothing extra. This sets no bit.
Packit 514978
.SH RETURN VALUE
Packit 514978
Upon successful completion, ares_library_init() will return 0.  Otherwise, a
Packit 514978
non-zero error number will be returned to indicate the error. Except for
Packit 514978
\fIares_strerror(3)\fP, you shall not call any other c-ares function upon
Packit 514978
\fIares_library_init(3)\fP failure.
Packit 514978
.SH AVAILABILITY
Packit 514978
This function was first introduced in c-ares version 1.7.0 along with the
Packit 514978
definition of preprocessor symbol \fICARES_HAVE_ARES_LIBRARY_INIT\fP as an
Packit 514978
indication of the availability of this function. Its recursive behavior,
Packit 514978
which requires a matching number of calls to \fIares_library_cleanup()\fP
Packit 514978
in order to deinitialize the library, is present since c-ares version
Packit 514978
1.10.0. Earlier versions would deinitialize the library on the first call
Packit 514978
to \fIares_library_cleanup()\fP.
Packit 514978
.PP
Packit 514978
Since the introduction of this function it is absolutely mandatory to
Packit 514978
call it for any Win32/64 program using c-ares.
Packit 514978
.PP
Packit 514978
Non-Win32/64 systems can still use c-ares version 1.7.0 without calling
Packit 514978
\fIares_library_init(3)\fP due to the fact that \fIcurrently\fP it is nearly
Packit 514978
a do-nothing function on non-Win32/64 platforms at this point.
Packit 514978
.SH SEE ALSO
Packit 514978
.BR ares_library_cleanup(3),
Packit 514978
.BR ares_strerror(3)
Packit 514978
.SH AUTHOR
Packit 514978
Yang Tse
Packit 514978
.PP
Packit 514978
Copyright 1998 by the Massachusetts Institute of Technology.
Packit 514978
.br
Packit 514978
Copyright (C) 2004-2009 by Daniel Stenberg.