@ -33,6 +33,7 @@ Contributors:
# include "packet_mosq.h"
# include "packet_mosq.h"
# include "will_mosq.h"
# include "will_mosq.h"
static unsigned int init_refcount = 0 ;
void mosquitto__destroy ( struct mosquitto * mosq ) ;
void mosquitto__destroy ( struct mosquitto * mosq ) ;
@ -46,6 +47,9 @@ int mosquitto_lib_version(int *major, int *minor, int *revision)
int mosquitto_lib_init ( void )
int mosquitto_lib_init ( void )
{
{
int rc ;
if ( init_refcount = = 0 ) {
# ifdef WIN32
# ifdef WIN32
srand ( GetTickCount64 ( ) ) ;
srand ( GetTickCount64 ( ) ) ;
# elif _POSIX_TIMERS>0 && defined(_POSIX_MONOTONIC_CLOCK)
# elif _POSIX_TIMERS>0 && defined(_POSIX_MONOTONIC_CLOCK)
@ -65,12 +69,25 @@ int mosquitto_lib_init(void)
srand ( tv . tv_sec * 1000 + tv . tv_usec / 1000 ) ;
srand ( tv . tv_sec * 1000 + tv . tv_usec / 1000 ) ;
# endif
# endif
return net__init ( ) ;
rc = net__init ( ) ;
if ( rc ! = MOSQ_ERR_SUCCESS ) {
return rc ;
}
}
init_refcount + + ;
return MOSQ_ERR_SUCCESS ;
}
}
int mosquitto_lib_cleanup ( void )
int mosquitto_lib_cleanup ( void )
{
{
if ( init_refcount = = 1 ) {
net__cleanup ( ) ;
net__cleanup ( ) ;
}
if ( init_refcount > 0 ) {
- - init_refcount ;
}
return MOSQ_ERR_SUCCESS ;
return MOSQ_ERR_SUCCESS ;
}
}