initialize udns_library on first use

This commit is contained in:
Torsten Dreyer 2016-11-20 16:11:24 +01:00
parent 43a8277bdb
commit d2e2603400

View File

@ -33,10 +33,15 @@ namespace DNS {
class Client::ClientPrivate { class Client::ClientPrivate {
public: public:
ClientPrivate() { ClientPrivate() {
if( instanceCounter++ == 0 )
if (dns_init(NULL, 0) < 0)
SG_LOG(SG_IO, SG_ALERT, "Can't init udns library" );
ctx = dns_new(NULL); ctx = dns_new(NULL);
if (dns_init(ctx, 0) < 0) if (dns_init(ctx, 0) < 0)
SG_LOG(SG_IO, SG_ALERT, "Can't init udns library" ); SG_LOG(SG_IO, SG_ALERT, "Can't create udns context" );
if( dns_open(ctx) < 0 ) if( dns_open(ctx) < 0 )
SG_LOG(SG_IO, SG_ALERT, "Can't open udns context" ); SG_LOG(SG_IO, SG_ALERT, "Can't open udns context" );
@ -45,11 +50,16 @@ public:
~ClientPrivate() { ~ClientPrivate() {
dns_close(ctx); dns_close(ctx);
dns_free(ctx); dns_free(ctx);
if( --instanceCounter == 0 )
dns_close(NULL);
} }
struct dns_ctx * ctx; struct dns_ctx * ctx;
static size_t instanceCounter;
}; };
size_t Client::ClientPrivate::instanceCounter = 0;
Request::Request( const std::string & dn ) : Request::Request( const std::string & dn ) :
_dn(dn), _dn(dn),
_type(DNS_T_ANY), _type(DNS_T_ANY),