Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lev micro stops when server stops #114

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.13)
project(cnats)
include(CTest)
include(FindPackageHandleStandardArgs)
include(CMakePackageConfigHelpers)

# Uncomment to have the build process verbose
# set(CMAKE_VERBOSE_MAKEFILE TRUE)
Expand Down Expand Up @@ -258,6 +259,11 @@ set(NATS_VERSION_SUFFIX "-beta")

set(NATS_VERSION_REQUIRED_NUMBER 0x030900)

write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/cnats-config-version.cmake"
COMPATIBILITY SameMinorVersion
VERSION ${NATS_VERSION_MAJOR}.${NATS_VERSION_MINOR}.${NATS_VERSION_PATCH}${NATS_VERSION_SUFFIX})

if(NATS_UPDATE_VERSION OR NATS_UPDATE_DOC)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in
Expand Down
2 changes: 1 addition & 1 deletion examples/micro-sequence.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static microError *handle_sequence(microRequest *req)
result_len = snprintf(result, sizeof(result), "%Lf", value);
if (err == NULL)
err = microRequest_Respond(req, result, result_len);

microArgs_Destroy(args);
return err;
}
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ if(NATS_BUILD_LIB_SHARED)
NAMESPACE cnats::
FILE cnats-config.cmake
DESTINATION ${NATS_LIBDIR}/cmake/cnats)
install(FILES "${PROJECT_BINARY_DIR}/cnats-config-version.cmake"
DESTINATION ${NATS_LIBDIR}/cmake/cnats)
endif(NATS_BUILD_LIB_SHARED)

if(NATS_BUILD_LIB_STATIC)
Expand All @@ -79,6 +81,8 @@ if(NATS_BUILD_LIB_STATIC)
NAMESPACE cnats::
FILE cnats-config.cmake
DESTINATION ${NATS_LIBDIR}/cmake/cnats)
install(FILES "${PROJECT_BINARY_DIR}/cnats-config-version.cmake"
DESTINATION ${NATS_LIBDIR}/cmake/cnats)
endif(NATS_BUILD_LIB_STATIC)

install(FILES deprnats.h DESTINATION ${NATS_INCLUDE_DIR} RENAME nats.h)
Expand Down
4 changes: 4 additions & 0 deletions src/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ _freeConn(natsConnection *nc)
natsStrHash_Destroy(nc->respMap);
natsCondition_Destroy(nc->reconnectCond);
natsMutex_Destroy(nc->subsMu);
natsMutex_Destroy(nc->servicesMu);
natsMutex_Destroy(nc->mu);
NATS_FREE(nc->services);

NATS_FREE(nc);

Expand Down Expand Up @@ -3238,6 +3240,8 @@ natsConn_create(natsConnection **newConn, natsOptions *options)
s = natsMutex_Create(&(nc->mu));
if (s == NATS_OK)
s = natsMutex_Create(&(nc->subsMu));
if (s == NATS_OK)
s = natsMutex_Create(&(nc->servicesMu));
if (s == NATS_OK)
s = _setupServerPool(nc);
if (s == NATS_OK)
Expand Down
41 changes: 0 additions & 41 deletions src/glib/glib.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ _freeLib(void)
nats_freeDispatcherPool(&gLib.replyDispatchers);

natsNUID_free();
natsMutex_Destroy(gLib.service_callback_mu);
natsHash_Destroy(gLib.all_services_to_callback);

natsCondition_Destroy(gLib.cond);

Expand Down Expand Up @@ -290,11 +288,6 @@ nats_openLib(natsClientConfig *config)
if (s == NATS_OK)
s = nats_initDispatcherPool(&(gLib.replyDispatchers), config->ReplyThreadPoolMax);

if (s == NATS_OK)
s = natsMutex_Create(&gLib.service_callback_mu);
if (s == NATS_OK)
s = natsHash_Create(&gLib.all_services_to_callback, 8);

if (s == NATS_OK)
gLib.initialized = true;

Expand Down Expand Up @@ -443,40 +436,6 @@ void nats_ReleaseThreadMemory(void)
natsMutex_Unlock(gLib.lock);
}

natsStatus
natsLib_startServiceCallbacks(microService *m)
{
natsStatus s;

natsMutex_Lock(gLib.service_callback_mu);
s = natsHash_Set(gLib.all_services_to_callback, (int64_t)m, (void *)m, NULL);
natsMutex_Unlock(gLib.service_callback_mu);

return NATS_UPDATE_ERR_STACK(s);
}

void natsLib_stopServiceCallbacks(microService *m)
{
if (m == NULL)
return;

natsMutex_Lock(gLib.service_callback_mu);
natsHash_Remove(gLib.all_services_to_callback, (int64_t)m);
natsMutex_Unlock(gLib.service_callback_mu);
}

natsMutex *
natsLib_getServiceCallbackMutex(void)
{
return gLib.service_callback_mu;
}

natsHash *
natsLib_getAllServicesToCallback(void)
{
return gLib.all_services_to_callback;
}

natsClientConfig *nats_testInspectClientConfig(void)
{
// Immutable after startup
Expand Down
5 changes: 0 additions & 5 deletions src/glib/glibp.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ typedef struct __natsLib

natsGCList gc;

// For micro services code
natsMutex *service_callback_mu;
// uses `microService*` as the key and the value.
natsHash *all_services_to_callback;

} natsLib;

natsLib *nats_lib(void);
Expand Down
Loading