提交 5d682abd authored 作者: Shane Bryldt's avatar Shane Bryldt

FS-10167: Major updates to lifecycle management across a number of objects…

FS-10167: Major updates to lifecycle management across a number of objects changing a number of architecture related areas, fixed some little bugs, too much to remember exactly
上级 87db0852
......@@ -193,7 +193,6 @@
<ClCompile Include="src\blade_identity.c" />
<ClCompile Include="src\blade_method.c" />
<ClCompile Include="src\blade_module.c" />
<ClCompile Include="src\blade_module_chat.c" />
<ClCompile Include="src\blade_module_wss.c" />
<ClCompile Include="src\blade_protocol.c" />
<ClCompile Include="src\blade_session.c" />
......@@ -220,6 +219,7 @@
<ClInclude Include="src\include\blade_identity.h" />
<ClInclude Include="src\include\blade_method.h" />
<ClInclude Include="src\include\blade_module.h" />
<ClInclude Include="src\include\blade_module_wss.h" />
<ClInclude Include="src\include\blade_protocol.h" />
<ClInclude Include="src\include\blade_session.h" />
<ClInclude Include="src\include\blade_space.h" />
......
......@@ -36,9 +36,6 @@
<ClCompile Include="src\blade_module.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\blade_module_chat.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\blade_module_wss.c">
<Filter>Source Files</Filter>
</ClCompile>
......@@ -137,5 +134,8 @@
<ClInclude Include="src\include\ks_dht-int.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\include\blade_module_wss.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -40,7 +40,11 @@ KS_DECLARE(ks_status_t) blade_init(void)
KS_DECLARE(ks_status_t) blade_shutdown(void)
{
return ks_shutdown();
ks_status_t ret = ks_shutdown();
#ifdef _WINDOWS_
_CrtDumpMemoryLeaks();
#endif
return ret;
}
/* For Emacs:
......
......@@ -132,8 +132,6 @@ KS_DECLARE(ks_status_t) blade_connection_destroy(blade_connection_t **bcP)
//ks_pool_free(bc->pool, bcP);
ks_pool_close(&pool);
ks_log(KS_LOG_DEBUG, "Destroyed\n");
*bcP = NULL;
return KS_STATUS_SUCCESS;
......
......@@ -45,6 +45,25 @@ struct blade_identity_s {
ks_hash_t *parameters;
};
// @todo missed a structure to use cleanup callbacks
static void blade_identity_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
{
blade_identity_t *bi = (blade_identity_t *)ptr;
ks_assert(bi);
switch (action) {
case KS_MPCL_ANNOUNCE:
break;
case KS_MPCL_TEARDOWN:
if (bi->uri) ks_pool_free(bi->pool, &bi->uri);
if (bi->components) ks_pool_free(bi->pool, &bi->components);
if (bi->parameters) ks_hash_destroy(&bi->parameters);
break;
case KS_MPCL_DESTROY:
break;
}
}
KS_DECLARE(ks_status_t) blade_identity_create(blade_identity_t **biP, ks_pool_t *pool)
{
......@@ -55,6 +74,9 @@ KS_DECLARE(ks_status_t) blade_identity_create(blade_identity_t **biP, ks_pool_t
bi = ks_pool_alloc(pool, sizeof(blade_identity_t));
bi->pool = pool;
ks_assert(ks_pool_set_cleanup(pool, bi, NULL, blade_identity_cleanup) == KS_STATUS_SUCCESS);
*biP = bi;
return KS_STATUS_SUCCESS;
......
......@@ -44,6 +44,22 @@ struct blade_method_s {
// @todo more fun descriptive information about the call for remote registrations
};
static void blade_method_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
{
blade_method_t *bm = (blade_method_t *)ptr;
ks_assert(bm);
switch (action) {
case KS_MPCL_ANNOUNCE:
break;
case KS_MPCL_TEARDOWN:
ks_pool_free(bm->pool, &bm->name);
break;
case KS_MPCL_DESTROY:
break;
}
}
KS_DECLARE(ks_status_t) blade_method_create(blade_method_t **bmP, blade_space_t *bs, const char *name, blade_request_callback_t callback)
{
......@@ -58,35 +74,19 @@ KS_DECLARE(ks_status_t) blade_method_create(blade_method_t **bmP, blade_space_t
bh = blade_space_handle_get(bs);
ks_assert(bh);
pool = blade_handle_pool_get(bh);
pool = blade_space_pool_get(bs);
ks_assert(pool);
bm = ks_pool_alloc(pool, sizeof(blade_method_t));
bm->handle = bh;
bm->pool = pool;
bm->space = bs;
bm->name = name; // @todo dup and keep copy? should mostly be literals
bm->name = ks_pstrdup(pool, name);
bm->callback = callback;
*bmP = bm;
ks_log(KS_LOG_DEBUG, "Method Created: %s.%s\n", blade_space_path_get(bs), name);
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_method_destroy(blade_method_t **bmP)
{
blade_method_t *bm = NULL;
ks_assert(ks_pool_set_cleanup(pool, bm, NULL, blade_method_cleanup) == KS_STATUS_SUCCESS);
ks_assert(bmP);
ks_assert(*bmP);
bm = *bmP;
ks_log(KS_LOG_DEBUG, "Method Destroyed: %s.%s\n", blade_space_path_get(bm->space), bm->name);
ks_pool_free(bm->pool, bmP);
*bmP = bm;
return KS_STATUS_SUCCESS;
}
......
......@@ -36,6 +36,7 @@
struct blade_module_s {
blade_handle_t *handle;
ks_pool_t *pool;
const char *id;
void *module_data;
blade_module_callbacks_t *module_callbacks;
......@@ -60,6 +61,7 @@ static void blade_module_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_
KS_DECLARE(ks_status_t) blade_module_create(blade_module_t **bmP, blade_handle_t *bh, ks_pool_t *pool, void *module_data, blade_module_callbacks_t *module_callbacks)
{
blade_module_t *bm = NULL;
uuid_t uuid;
ks_assert(bmP);
ks_assert(bh);
......@@ -67,9 +69,12 @@ KS_DECLARE(ks_status_t) blade_module_create(blade_module_t **bmP, blade_handle_t
ks_assert(module_data);
ks_assert(module_callbacks);
ks_uuid(&uuid);
bm = ks_pool_alloc(pool, sizeof(blade_module_t));
bm->handle = bh;
bm->pool = pool;
bm->id = ks_uuid_str(pool, &uuid);
bm->module_data = module_data;
bm->module_callbacks = module_callbacks;
......@@ -82,6 +87,25 @@ KS_DECLARE(ks_status_t) blade_module_create(blade_module_t **bmP, blade_handle_t
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_module_destroy(blade_module_t **bmP)
{
blade_module_t *bm = NULL;
ks_pool_t *pool = NULL;
ks_assert(bmP);
ks_assert(*bmP);
bm = *bmP;
pool = bm->pool;
//ks_pool_free(bm->pool, bmP);
ks_pool_close(&pool);
*bmP = NULL;
return KS_STATUS_SUCCESS;
}
KS_DECLARE(blade_handle_t *) blade_module_handle_get(blade_module_t *bm)
{
ks_assert(bm);
......@@ -89,6 +113,20 @@ KS_DECLARE(blade_handle_t *) blade_module_handle_get(blade_module_t *bm)
return bm->handle;
}
KS_DECLARE(ks_pool_t *) blade_module_pool_get(blade_module_t *bm)
{
ks_assert(bm);
return bm->pool;
}
KS_DECLARE(const char *) blade_module_id_get(blade_module_t *bm)
{
ks_assert(bm);
return bm->id;
}
KS_DECLARE(void *) blade_module_data_get(blade_module_t *bm)
{
ks_assert(bm);
......@@ -96,6 +134,12 @@ KS_DECLARE(void *) blade_module_data_get(blade_module_t *bm)
return bm->module_data;
}
KS_DECLARE(blade_module_callbacks_t *) blade_module_callbacks_get(blade_module_t *bm)
{
ks_assert(bm);
return bm->module_callbacks;
}
/* For Emacs:
* Local Variables:
......
差异被折叠。
......@@ -69,20 +69,10 @@ struct blade_transport_wss_s {
ks_status_t blade_module_wss_create(blade_module_wss_t **bm_wssP, blade_handle_t *bh);
ks_status_t blade_module_wss_destroy(blade_module_wss_t **bm_wssP);
// @todo remove exporting this, it's only temporary until DSO loading is in place so wss module can be loaded
KS_DECLARE(ks_status_t) blade_module_wss_on_load(blade_module_t **bmP, blade_handle_t *bh);
KS_DECLARE(ks_status_t) blade_module_wss_on_unload(blade_module_t *bm);
KS_DECLARE(ks_status_t) blade_module_wss_on_startup(blade_module_t *bm, config_setting_t *config);
KS_DECLARE(ks_status_t) blade_module_wss_on_shutdown(blade_module_t *bm);
ks_status_t blade_module_wss_listen(blade_module_wss_t *bm, ks_sockaddr_t *addr);
void *blade_module_wss_listeners_thread(ks_thread_t *thread, void *data);
ks_status_t blade_transport_wss_create(blade_transport_wss_t **bt_wssP, ks_pool_t *pool, blade_module_wss_t *bm_wss, ks_socket_t sock, const char *session_id);
ks_status_t blade_transport_wss_on_connect(blade_connection_t **bcP, blade_module_t *bm, blade_identity_t *target, const char *session_id);
......@@ -107,8 +97,6 @@ blade_connection_state_hook_t blade_transport_wss_on_state_ready_outbound(blade_
static blade_module_callbacks_t g_module_wss_callbacks =
{
blade_module_wss_on_load,
blade_module_wss_on_unload,
blade_module_wss_on_startup,
blade_module_wss_on_shutdown,
};
......@@ -145,19 +133,18 @@ static void blade_module_wss_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_p
case KS_MPCL_ANNOUNCE:
break;
case KS_MPCL_TEARDOWN:
blade_module_wss_on_shutdown(bm_wss->module);
break;
case KS_MPCL_DESTROY:
break;
}
}
ks_status_t blade_module_wss_create(blade_module_wss_t **bm_wssP, blade_handle_t *bh)
KS_DECLARE(ks_status_t) blade_module_wss_create(blade_module_t **bmP, blade_handle_t *bh)
{
blade_module_wss_t *bm_wss = NULL;
ks_pool_t *pool = NULL;
ks_assert(bm_wssP);
ks_assert(bmP);
ks_assert(bh);
ks_pool_open(&pool);
......@@ -175,63 +162,11 @@ ks_status_t blade_module_wss_create(blade_module_wss_t **bm_wssP, blade_handle_t
ks_log(KS_LOG_DEBUG, "Created\n");
*bm_wssP = bm_wss;
return KS_STATUS_SUCCESS;
}
ks_status_t blade_module_wss_destroy(blade_module_wss_t **bm_wssP)
{
blade_module_wss_t *bm_wss = NULL;
ks_pool_t *pool = NULL;
ks_assert(bm_wssP);
ks_assert(*bm_wssP);
bm_wss = *bm_wssP;
pool = bm_wss->pool;
//ks_pool_free(bm_wss->pool, bm_wssP);
ks_pool_close(&pool);
ks_log(KS_LOG_DEBUG, "Destroyed\n");
*bm_wssP = NULL;
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_module_wss_on_load(blade_module_t **bmP, blade_handle_t *bh)
{
blade_module_wss_t *bm_wss = NULL;
ks_assert(bmP);
ks_assert(bh);
blade_module_wss_create(&bm_wss, bh);
ks_assert(bm_wss);
*bmP = bm_wss->module;
ks_log(KS_LOG_DEBUG, "Loaded\n");
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_module_wss_on_unload(blade_module_t *bm)
{
blade_module_wss_t *bm_wss = NULL;
ks_assert(bm);
bm_wss = blade_module_data_get(bm);
blade_module_wss_destroy(&bm_wss);
ks_log(KS_LOG_DEBUG, "Unloaded\n");
return KS_STATUS_SUCCESS;
}
ks_status_t blade_module_wss_config(blade_module_wss_t *bm_wss, config_setting_t *config)
{
......
......@@ -33,23 +33,39 @@
#include "blade.h"
static void blade_request_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
{
blade_request_t *breq = (blade_request_t *)ptr;
ks_assert(breq);
switch (action) {
case KS_MPCL_ANNOUNCE:
break;
case KS_MPCL_TEARDOWN:
ks_pool_free(breq->pool, (void **)&breq->session_id);
cJSON_Delete(breq->message);
break;
case KS_MPCL_DESTROY:
break;
}
}
KS_DECLARE(ks_status_t) blade_request_create(blade_request_t **breqP,
blade_handle_t *bh,
ks_pool_t *pool,
const char *session_id,
cJSON *json,
blade_response_callback_t callback)
{
blade_request_t *breq = NULL;
ks_pool_t *pool = NULL;
ks_assert(breqP);
ks_assert(bh);
ks_assert(pool);
ks_assert(session_id);
ks_assert(json);
pool = blade_handle_pool_get(bh);
ks_assert(pool);
breq = ks_pool_alloc(pool, sizeof(blade_request_t));
breq->handle = bh;
breq->pool = pool;
......@@ -58,6 +74,8 @@ KS_DECLARE(ks_status_t) blade_request_create(blade_request_t **breqP,
breq->message_id = cJSON_GetObjectCstr(breq->message, "id");
breq->callback = callback;
ks_assert(ks_pool_set_cleanup(pool, breq, NULL, blade_request_cleanup) == KS_STATUS_SUCCESS);
*breqP = breq;
return KS_STATUS_SUCCESS;
......@@ -72,33 +90,46 @@ KS_DECLARE(ks_status_t) blade_request_destroy(blade_request_t **breqP)
breq = *breqP;
ks_pool_free(breq->pool, (void **)&breq->session_id);
cJSON_Delete(breq->message);
ks_pool_free(breq->pool, breqP);
return KS_STATUS_SUCCESS;
}
static void blade_response_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
{
blade_response_t *bres = (blade_response_t *)ptr;
ks_assert(bres);
switch (action) {
case KS_MPCL_ANNOUNCE:
break;
case KS_MPCL_TEARDOWN:
ks_pool_free(bres->pool, (void **)&bres->session_id);
blade_request_destroy(&bres->request);
cJSON_Delete(bres->message);
break;
case KS_MPCL_DESTROY:
break;
}
}
KS_DECLARE(ks_status_t) blade_response_create(blade_response_t **bresP,
blade_handle_t *bh,
ks_pool_t *pool,
const char *session_id,
blade_request_t *breq,
cJSON *json)
{
blade_response_t *bres = NULL;
ks_pool_t *pool = NULL;
ks_assert(bresP);
ks_assert(bh);
ks_assert(pool);
ks_assert(session_id);
ks_assert(breq);
ks_assert(json);
pool = blade_handle_pool_get(bh);
ks_assert(pool);
bres = ks_pool_alloc(pool, sizeof(blade_response_t));
bres->handle = bh;
bres->pool = pool;
......@@ -106,6 +137,8 @@ KS_DECLARE(ks_status_t) blade_response_create(blade_response_t **bresP,
bres->request = breq;
bres->message = cJSON_Duplicate(json, 1);
ks_assert(ks_pool_set_cleanup(pool, bres, NULL, blade_response_cleanup) == KS_STATUS_SUCCESS);
*bresP = bres;
return KS_STATUS_SUCCESS;
......@@ -120,37 +153,51 @@ KS_DECLARE(ks_status_t) blade_response_destroy(blade_response_t **bresP)
bres = *bresP;
ks_pool_free(bres->pool, (void **)&bres->session_id);
blade_request_destroy(&bres->request);
cJSON_Delete(bres->message);
ks_pool_free(bres->pool, bresP);
return KS_STATUS_SUCCESS;
}
static void blade_event_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
{
blade_event_t *bev = (blade_event_t *)ptr;
ks_assert(bev);
switch (action) {
case KS_MPCL_ANNOUNCE:
break;
case KS_MPCL_TEARDOWN:
ks_pool_free(bev->pool, &bev->session_id);
cJSON_Delete(bev->message);
break;
case KS_MPCL_DESTROY:
break;
}
}
KS_DECLARE(ks_status_t) blade_event_create(blade_event_t **bevP,
blade_handle_t *bh,
ks_pool_t *pool,
const char *session_id,
cJSON *json)
{
blade_event_t *bev = NULL;
ks_pool_t *pool = NULL;
ks_assert(bevP);
ks_assert(bh);
ks_assert(pool);
ks_assert(session_id);
ks_assert(json);
pool = blade_handle_pool_get(bh);
ks_assert(pool);
bev = ks_pool_alloc(pool, sizeof(blade_event_t));
bev->handle = bh;
bev->pool = pool;
bev->session_id = ks_pstrdup(pool, session_id);
bev->message = cJSON_Duplicate(json, 1);
ks_assert(ks_pool_set_cleanup(pool, bev, NULL, blade_event_cleanup) == KS_STATUS_SUCCESS);
*bevP = bev;
return KS_STATUS_SUCCESS;
......@@ -165,14 +212,12 @@ KS_DECLARE(ks_status_t) blade_event_destroy(blade_event_t **bevP)
bev = *bevP;
ks_pool_free(bev->pool, (void **)&bev->session_id);
cJSON_Delete(bev->message);
ks_pool_free(bev->pool, bevP);
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_rpc_request_create(ks_pool_t *pool, cJSON **json, cJSON **params, const char **id, const char *method)
{
cJSON *root = NULL;
......
......@@ -163,8 +163,6 @@ KS_DECLARE(ks_status_t) blade_session_destroy(blade_session_t **bsP)
//ks_pool_free(bs->pool, bsP);
ks_pool_close(&pool);
ks_log(KS_LOG_DEBUG, "Destroyed\n");
*bsP = NULL;
return KS_STATUS_SUCCESS;
......@@ -617,7 +615,7 @@ KS_DECLARE(ks_status_t) blade_session_send(blade_session_t *bs, cJSON *json, bla
// 1) Sending a request (client: method caller or consumer)
ks_log(KS_LOG_DEBUG, "Session (%s) sending request (%s) for %s\n", bs->id, id, method);
blade_request_create(&request, bs->handle, bs->id, json, callback);
blade_request_create(&request, bs->handle, blade_handle_pool_get(bs->handle), bs->id, json, callback);
ks_assert(request);
// @todo set request TTL and figure out when requests are checked for expiration (separate thread in the handle?)
......@@ -681,7 +679,7 @@ ks_status_t blade_session_process(blade_session_t *bs, cJSON *json)
} else {
ks_log(KS_LOG_DEBUG, "Session (%s) processing event %s\n", bs->id, blade_event);
blade_event_create(&bev, bs->handle, bs->id, json);
blade_event_create(&bev, bs->handle, bs->pool, bs->id, json);
ks_assert(bev);
disconnect = callback(bev);
......@@ -736,7 +734,7 @@ ks_status_t blade_session_process(blade_session_t *bs, cJSON *json)
callback = blade_method_callback_get(tmp_method);
ks_assert(callback);
blade_request_create(&breq, bs->handle, bs->id, json, NULL);
blade_request_create(&breq, bs->handle, blade_handle_pool_get(bs->handle), bs->id, json, NULL);
ks_assert(breq);
disconnect = callback(blade_space_module_get(tmp_space), breq);
......@@ -755,7 +753,7 @@ ks_status_t blade_session_process(blade_session_t *bs, cJSON *json)
}
blade_handle_requests_remove(breq);
blade_response_create(&bres, bs->handle, bs->id, breq, json);
blade_response_create(&bres, bs->handle, bs->pool, bs->id, breq, json);
ks_assert(bres);
disconnect = breq->callback(bres);
......
......@@ -42,6 +42,23 @@ struct blade_space_s {
ks_hash_t *methods;
};
static void blade_space_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
{
blade_space_t *bs = (blade_space_t *)ptr;
ks_assert(bs);
switch (action) {
case KS_MPCL_ANNOUNCE:
break;
case KS_MPCL_TEARDOWN:
ks_pool_free(bs->pool, &bs->path);
ks_hash_destroy(&bs->methods);
break;
case KS_MPCL_DESTROY:
break;
}
}
KS_DECLARE(ks_status_t) blade_space_create(blade_space_t **bsP, blade_handle_t *bh, blade_module_t *bm, const char *path)
{
......@@ -52,16 +69,19 @@ KS_DECLARE(ks_status_t) blade_space_create(blade_space_t **bsP, blade_handle_t *
ks_assert(bh);
ks_assert(path);
pool = blade_handle_pool_get(bh);
pool = blade_module_pool_get(bm);
ks_assert(pool);
bs = ks_pool_alloc(pool, sizeof(blade_space_t));
bs->handle = bh;
bs->pool = pool;
bs->module = bm;
bs->path = path; // @todo dup and keep copy? should mostly be literals
ks_hash_create(&bs->methods, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_NOLOCK | KS_HASH_FLAG_DUP_CHECK, bs->pool);
bs->path = ks_pstrdup(pool, path);
ks_hash_create(&bs->methods, KS_HASH_MODE_CASE_INSENSITIVE, KS_HASH_FLAG_RWLOCK | KS_HASH_FLAG_DUP_CHECK | KS_HASH_FLAG_FREE_VALUE, bs->pool);
ks_assert(bs);
ks_assert(ks_pool_set_cleanup(pool, bs, NULL, blade_space_cleanup) == KS_STATUS_SUCCESS);
*bsP = bs;
ks_log(KS_LOG_DEBUG, "Space Created: %s\n", path);
......@@ -69,38 +89,18 @@ KS_DECLARE(ks_status_t) blade_space_create(blade_space_t **bsP, blade_handle_t *
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_space_destroy(blade_space_t **bsP)
KS_DECLARE(blade_handle_t *) blade_space_handle_get(blade_space_t *bs)
{
blade_space_t *bs = NULL;
ks_hash_iterator_t *it = NULL;
ks_assert(bsP);
ks_assert(*bsP);
bs = *bsP;
for (it = ks_hash_first(bs->methods, KS_UNLOCKED); it; it = ks_hash_next(&it)) {
void *key = NULL;
blade_method_t *value = NULL;
ks_hash_this(it, (const void **)&key, NULL, (void **)&value);
blade_method_destroy(&value);
}
ks_hash_destroy(&bs->methods);
ks_log(KS_LOG_DEBUG, "Space Destroyed: %s\n", bs->path);
ks_pool_free(bs->pool, bsP);
ks_assert(bs);
return KS_STATUS_SUCCESS;
return bs->handle;
}
KS_DECLARE(blade_handle_t *) blade_space_handle_get(blade_space_t *bs)
KS_DECLARE(ks_pool_t *) blade_space_pool_get(blade_space_t *bs)
{
ks_assert(bs);
return bs->handle;
return bs->pool;
}
KS_DECLARE(blade_module_t *) blade_space_module_get(blade_space_t *bs)
......@@ -119,9 +119,7 @@ KS_DECLARE(const char *) blade_space_path_get(blade_space_t *bs)
KS_DECLARE(ks_status_t) blade_space_methods_add(blade_space_t *bs, blade_method_t *bm)
{
ks_status_t ret = KS_STATUS_SUCCESS;
const char *name = NULL;
blade_method_t *bm_old = NULL;
ks_assert(bs);
ks_assert(bm);
......@@ -129,20 +127,13 @@ KS_DECLARE(ks_status_t) blade_space_methods_add(blade_space_t *bs, blade_method_
name = blade_method_name_get(bm);
ks_assert(name);
ks_hash_write_lock(bs->methods);
bm_old = ks_hash_search(bs->methods, (void *)name, KS_UNLOCKED);
if (bm_old) ks_hash_remove(bs->methods, (void *)name);
ret = ks_hash_insert(bs->methods, (void *)name, (void *)bm);
ks_hash_write_unlock(bs->methods);
if (bm_old) blade_method_destroy(&bm_old);
ks_hash_insert(bs->methods, (void *)name, (void *)bm);
return ret;
return KS_STATUS_SUCCESS;
}
KS_DECLARE(ks_status_t) blade_space_methods_remove(blade_space_t *bs, blade_method_t *bm)
{
ks_status_t ret = KS_STATUS_SUCCESS;
const char *name = NULL;
ks_assert(bs);
......@@ -151,22 +142,18 @@ KS_DECLARE(ks_status_t) blade_space_methods_remove(blade_space_t *bs, blade_meth
name = blade_method_name_get(bm);
ks_assert(name);
ks_hash_write_lock(bs->methods);
ks_hash_remove(bs->methods, (void *)name);
ks_hash_write_unlock(bs->methods);
return ret;
return KS_STATUS_SUCCESS;
}
KS_DECLARE(blade_method_t *) blade_space_methods_get(blade_space_t *bs, const char *name)
{
blade_method_t *bm = NULL;
ks_assert(bs);
ks_assert(name);
ks_hash_read_lock(bs->methods);
bm = ks_hash_search(bs->methods, (void *)name, KS_UNLOCKED);
bm = ks_hash_search(bs->methods, (void *)name, KS_READLOCKED);
ks_hash_read_unlock(bs->methods);
return bm;
......
......@@ -51,6 +51,8 @@
#include "ks_dht.h"
#include "ks_bencode.h"
#include "blade_module_wss.h"
KS_BEGIN_EXTERN_C
#ifdef _WIN32
......
......@@ -37,7 +37,6 @@
KS_BEGIN_EXTERN_C
KS_DECLARE(ks_status_t) blade_method_create(blade_method_t **bmP, blade_space_t *bs, const char *name, blade_request_callback_t callback);
KS_DECLARE(ks_status_t) blade_method_destroy(blade_method_t **bmP);
KS_DECLARE(const char *) blade_method_name_get(blade_method_t *bm);
KS_DECLARE(blade_request_callback_t) blade_method_callback_get(blade_method_t *bm);
KS_END_EXTERN_C
......
......@@ -36,20 +36,15 @@
#include <blade.h>
KS_BEGIN_EXTERN_C
KS_DECLARE(ks_status_t) blade_module_create(blade_module_t **bmP, blade_handle_t *bh, ks_pool_t *pool, void *module_data, blade_module_callbacks_t *module_callbacks);
KS_DECLARE(ks_status_t) blade_module_destroy(blade_module_t **bmP);
KS_DECLARE(blade_handle_t *) blade_module_handle_get(blade_module_t *bm);
KS_DECLARE(ks_pool_t *) blade_module_pool_get(blade_module_t *bm);
KS_DECLARE(const char *) blade_module_id_get(blade_module_t *bm);
KS_DECLARE(void *) blade_module_data_get(blade_module_t *bm);
KS_DECLARE(blade_module_callbacks_t *) blade_module_callbacks_get(blade_module_t *bm);
// @todo very temporary, this is just here to get the wss module loaded until DSO is in place
KS_DECLARE(ks_status_t) blade_module_wss_on_load(blade_module_t **bmP, blade_handle_t *bh);
KS_DECLARE(ks_status_t) blade_module_wss_on_unload(blade_module_t *bm);
KS_DECLARE(ks_status_t) blade_module_wss_on_startup(blade_module_t *bm, config_setting_t *config);
KS_DECLARE(ks_status_t) blade_module_wss_on_shutdown(blade_module_t *bm);
KS_DECLARE(ks_status_t) blade_module_chat_on_load(blade_module_t **bmP, blade_handle_t *bh);
KS_DECLARE(ks_status_t) blade_module_chat_on_unload(blade_module_t *bm);
KS_DECLARE(ks_status_t) blade_module_chat_on_startup(blade_module_t *bm, config_setting_t *config);
KS_DECLARE(ks_status_t) blade_module_chat_on_shutdown(blade_module_t *bm);
KS_END_EXTERN_C
#endif
......
/*
* Copyright (c) 2017, Shane Bryldt
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of the original author; nor the names of any contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _BLADE_MODULE_WSS_H_
#define _BLADE_MODULE_WSS_H_
#include <blade.h>
KS_BEGIN_EXTERN_C
KS_DECLARE(ks_status_t) blade_module_wss_create(blade_module_t **bmP, blade_handle_t *bh);
KS_DECLARE(ks_status_t) blade_module_wss_on_startup(blade_module_t *bm, config_setting_t *config);
KS_DECLARE(ks_status_t) blade_module_wss_on_shutdown(blade_module_t *bm);
KS_END_EXTERN_C
#endif
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
*/
......@@ -38,13 +38,14 @@
KS_BEGIN_EXTERN_C
KS_DECLARE(ks_status_t) blade_request_create(blade_request_t **breqP,
blade_handle_t *bh,
ks_pool_t *pool,
const char *session_id,
cJSON *json,
blade_response_callback_t callback);
KS_DECLARE(ks_status_t) blade_request_destroy(blade_request_t **breqP);
KS_DECLARE(ks_status_t) blade_response_create(blade_response_t **bresP, blade_handle_t *bh, const char *session_id, blade_request_t *breq, cJSON *json);
KS_DECLARE(ks_status_t) blade_response_create(blade_response_t **bresP, blade_handle_t *bh, ks_pool_t *pool, const char *session_id, blade_request_t *breq, cJSON *json);
KS_DECLARE(ks_status_t) blade_response_destroy(blade_response_t **bresP);
KS_DECLARE(ks_status_t) blade_event_create(blade_event_t **bevP, blade_handle_t *bh, const char *session_id, cJSON *json);
KS_DECLARE(ks_status_t) blade_event_create(blade_event_t **bevP, blade_handle_t *bh, ks_pool_t *pool, const char *session_id, cJSON *json);
KS_DECLARE(ks_status_t) blade_event_destroy(blade_event_t **bevP);
KS_DECLARE(ks_status_t) blade_rpc_request_create(ks_pool_t *pool, cJSON **json, cJSON **params, const char **id, const char *method);
KS_DECLARE(ks_status_t) blade_rpc_response_create(cJSON **json, cJSON **result, const char *id);
......
......@@ -37,8 +37,8 @@
KS_BEGIN_EXTERN_C
KS_DECLARE(ks_status_t) blade_space_create(blade_space_t **bsP, blade_handle_t *bh, blade_module_t *bm, const char *path);
KS_DECLARE(ks_status_t) blade_space_destroy(blade_space_t **bsP);
KS_DECLARE(blade_handle_t *) blade_space_handle_get(blade_space_t *bs);
KS_DECLARE(ks_pool_t *) blade_space_pool_get(blade_space_t *bs);
KS_DECLARE(blade_module_t *) blade_space_module_get(blade_space_t *bs);
KS_DECLARE(const char *) blade_space_path_get(blade_space_t *bs);
KS_DECLARE(ks_status_t) blade_space_methods_add(blade_space_t *bs, blade_method_t *bm);
......
......@@ -42,12 +42,15 @@
KS_BEGIN_EXTERN_C
KS_DECLARE(ks_status_t) blade_handle_destroy(blade_handle_t **bhP);
KS_DECLARE(ks_status_t) blade_handle_create(blade_handle_t **bhP, ks_pool_t *pool, ks_thread_pool_t *tpool);
KS_DECLARE(ks_status_t) blade_handle_create(blade_handle_t **bhP);
KS_DECLARE(ks_status_t) blade_handle_startup(blade_handle_t *bh, config_setting_t *config);
KS_DECLARE(ks_status_t) blade_handle_shutdown(blade_handle_t *bh);
KS_DECLARE(ks_pool_t *) blade_handle_pool_get(blade_handle_t *bh);
KS_DECLARE(ks_thread_pool_t *) blade_handle_tpool_get(blade_handle_t *bh);
KS_DECLARE(ks_status_t) blade_handle_module_register(blade_module_t *bm);
//KS_DECLARE(ks_status_t) blade_handle_module_unregister(blade_module_t *bm);
KS_DECLARE(ks_status_t) blade_handle_transport_register(blade_handle_t *bh, blade_module_t *bm, const char *name, blade_transport_callbacks_t *callbacks);
KS_DECLARE(ks_status_t) blade_handle_transport_unregister(blade_handle_t *bh, const char *name);
......
......@@ -116,14 +116,10 @@ typedef enum {
typedef ks_status_t (*blade_module_load_callback_t)(blade_module_t **bmP, blade_handle_t *bh);
typedef ks_status_t (*blade_module_unload_callback_t)(blade_module_t *bm);
typedef ks_status_t (*blade_module_startup_callback_t)(blade_module_t *bm, config_setting_t *config);
typedef ks_status_t (*blade_module_shutdown_callback_t)(blade_module_t *bm);
typedef ks_status_t(*blade_module_shutdown_callback_t)(blade_module_t *bm);
struct blade_module_callbacks_s {
blade_module_load_callback_t onload;
blade_module_unload_callback_t onunload;
blade_module_startup_callback_t onstartup;
blade_module_shutdown_callback_t onshutdown;
};
......
......@@ -93,7 +93,7 @@ struct bencode_type {
struct bencode *(*decode) (struct ben_decode_ctx *ctx);
int (*encode) (struct ben_encode_ctx *ctx, const struct bencode *b);
size_t (*get_size) (const struct bencode *b);
void (*free) (struct bencode *b);
void (*freer) (struct bencode *b);
int (*cmp) (const struct bencode *a, const struct bencode *b);
};
......
......@@ -1715,8 +1715,8 @@ void ben_free(struct bencode *b)
break;
case BENCODE_USER:
u = ben_user_cast(b);
if (u->info->free)
u->info->free(b);
if (u->info->freer)
u->info->freer(b);
break;
default:
die("invalid type: %d\n", b->type);
......
......@@ -37,7 +37,7 @@ int main(int argc, char **argv)
config_t config;
config_setting_t *config_blade = NULL;
blade_module_t *mod_wss = NULL;
//blade_identity_t *id = NULL;
blade_identity_t *id = NULL;
const char *cfgpath = "bladec.cfg";
const char *session_state_callback_id = NULL;
......@@ -45,7 +45,7 @@ int main(int argc, char **argv)
blade_init();
blade_handle_create(&bh, NULL, NULL);
blade_handle_create(&bh);
if (argc > 1) cfgpath = argv[1];
......@@ -71,26 +71,17 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
if (blade_module_wss_on_load(&mod_wss, bh) != KS_STATUS_SUCCESS) {
ks_log(KS_LOG_ERROR, "Blade WSS module load failed\n");
return EXIT_FAILURE;
}
if (blade_module_wss_on_startup(mod_wss, config_blade) != KS_STATUS_SUCCESS) {
ks_log(KS_LOG_ERROR, "Blade WSS module startup failed\n");
return EXIT_FAILURE;
}
blade_handle_event_register(bh, "blade.chat.message", on_blade_chat_message_event);
blade_handle_session_state_callback_register(bh, NULL, on_blade_session_state_callback, &session_state_callback_id);
loop(bh);
blade_handle_session_state_callback_unregister(bh, session_state_callback_id);
blade_module_wss_on_unload(mod_wss);
//blade_handle_session_state_callback_unregister(bh, session_state_callback_id);
blade_handle_destroy(&bh);
config_destroy(&config);
blade_shutdown();
return 0;
......@@ -120,10 +111,10 @@ void on_blade_session_state_callback(blade_session_t *bs, blade_session_state_co
if (condition == BLADE_SESSION_STATE_CONDITION_PRE) {
ks_log(KS_LOG_DEBUG, "Blade Session State Changed: %s, %d\n", blade_session_id_get(bs), state);
if (state == BLADE_SESSION_STATE_READY) {
//cJSON *req = NULL;
//blade_rpc_request_create(blade_session_pool_get(bs), &req, NULL, NULL, "blade.chat.join");
//blade_session_send(bs, req, on_blade_chat_join_response);
//cJSON_Delete(req);
cJSON *req = NULL;
blade_rpc_request_create(blade_handle_pool_get(blade_session_handle_get(bs)), &req, NULL, NULL, "blade.chat.join");
blade_session_send(bs, req, on_blade_chat_join_response);
cJSON_Delete(req);
}
}
}
......@@ -186,7 +177,7 @@ void process_console_input(blade_handle_t *bh, char *line)
void command_quit(blade_handle_t *bh, char *args)
{
ks_assert(bh);
//ks_assert(bh);
ks_assert(args);
ks_log(KS_LOG_DEBUG, "Shutting down\n");
......
......@@ -49,6 +49,7 @@ KS_BEGIN_EXTERN_C
#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#endif
#define _CRTDBG_MAP_ALLOC
#endif
#ifndef _GNU_SOURCE
......@@ -96,6 +97,7 @@ KS_BEGIN_EXTERN_C
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
#include <crtdbg.h>
#else
#include <sys/time.h>
#include <sys/select.h>
......
......@@ -102,7 +102,11 @@ KS_DECLARE(void) ks_ssl_destroy_ssl_locks(void)
OPENSSL_free(ssl_mutexes);
ssl_count--;
if (ssl_pool) ks_pool_close(&ssl_pool);
}
SSL_COMP_free_compression_methods();
EVP_cleanup();
}
......
......@@ -128,7 +128,7 @@ static void *worker_thread(ks_thread_t *thread, void *data)
void *pop = NULL;
ks_status_t status;
status = ks_q_pop_timeout(tp->q, &pop, 1000);
status = ks_q_pop_timeout(tp->q, &pop, 100);
if (status == KS_STATUS_BREAK) {
if (tp->state != TP_STATE_RUNNING) {
break;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论