提交 a7add335 authored 作者: Shane Bryldt's avatar Shane Bryldt 提交者: Mike Jerris

FS-9952: Committing to show problem with ks_pool_resize

上级 d6d8ede6
......@@ -150,15 +150,12 @@ KS_DECLARE(const char *) blade_identity_uri(blade_identity_t *bi)
return bi->uri;
}
KS_DECLARE(ks_status_t) blade_identity_parameter_get(blade_identity_t *bi, const char *key, const char **value)
KS_DECLARE(const char *) blade_identity_parameter_get(blade_identity_t *bi, const char *key)
{
ks_assert(bi);
ks_assert(key);
ks_assert(value);
*value = (const char *)ks_hash_search(bi->parameters, (void *)key, KS_UNLOCKED);
return KS_STATUS_SUCCESS;
return (const char *)ks_hash_search(bi->parameters, (void *)key, KS_UNLOCKED);
}
......
......@@ -44,11 +44,12 @@ struct blade_handle_s {
ks_pool_t *pool;
ks_thread_pool_t *tpool;
config_setting_t *config_service;
config_setting_t *config_directory;
config_setting_t *config_datastore;
ks_hash_t *transports;
blade_identity_t *identity;
blade_datastore_t *datastore;
};
......@@ -164,7 +165,7 @@ KS_DECLARE(ks_status_t) blade_handle_destroy(blade_handle_t **bhP)
ks_status_t blade_handle_config(blade_handle_t *bh, config_setting_t *config)
{
config_setting_t *service = NULL;
config_setting_t *directory = NULL;
config_setting_t *datastore = NULL;
ks_assert(bh);
......@@ -172,13 +173,13 @@ ks_status_t blade_handle_config(blade_handle_t *bh, config_setting_t *config)
if (!config) return KS_STATUS_FAIL;
if (!config_setting_is_group(config)) return KS_STATUS_FAIL;
service = config_setting_get_member(config, "service");
directory = config_setting_get_member(config, "directory");
datastore = config_setting_get_member(config, "datastore");
//if (datastore && !config_setting_is_group(datastore)) return KS_STATUS_FAIL;
bh->config_service = service;
bh->config_directory = directory;
bh->config_datastore = datastore;
return KS_STATUS_SUCCESS;
......@@ -201,7 +202,11 @@ KS_DECLARE(ks_status_t) blade_handle_startup(blade_handle_t *bh, config_setting_
return KS_STATUS_FAIL;
}
}
// @todo load DSOs
// @todo call onload and onstartup callbacks for modules from DSOs
return KS_STATUS_SUCCESS;
}
......@@ -209,9 +214,12 @@ KS_DECLARE(ks_status_t) blade_handle_shutdown(blade_handle_t *bh)
{
ks_assert(bh);
// @todo cleanup registered transports
// @todo call onshutdown and onunload callbacks for modules from DSOs
// @todo unload DSOs
if (blade_handle_datastore_available(bh)) blade_datastore_destroy(&bh->datastore);
return KS_STATUS_SUCCESS;
}
......@@ -279,14 +287,33 @@ KS_DECLARE(ks_status_t) blade_handle_connect(blade_handle_t *bh, blade_connectio
ks_assert(bh);
ks_assert(target);
// @todo this should take a callback, and push this to a queue to be processed async from another thread on the handle
// which will allow the onconnect callback to block while doing things like DNS lookups without having unknown
// impact depending on the caller thread
ks_hash_read_lock(bh->transports);
blade_identity_parameter_get(target, "transport", &tname);
tname = blade_identity_parameter_get(target, "transport");
if (tname) {
bhtr = ks_hash_search(bh->transports, (void *)tname, KS_UNLOCKED);
if (!bhtr) {
// @todo error logging, target has an explicit transport that is not available in the local transports registry
// discuss later whether this scenario should still attempt other transports when target is explicit
// @note discussions indicate that by default messages should favor relaying through a master service, unless
// an existing direct connection already exists to the target (which if the target is the master node, then there is
// no conflict of proper routing). This also applies to routing for identities which relate to groups, relaying should
// most often occur through a master service, however there may be scenarios that exist where an existing session
// exists dedicated to faster delivery for a group (IE, through an ampq cluster directly, such as master services
// syncing with each other through a pub/sub). There is also the potential that instead of a separate session, the
// current session with a master service may be able to have another connection attached which represents access through
// amqp, which in turn acts as a preferred router for only group identities
// This information does not directly apply to connecting, but should be noted for the next level up where you simply
// send a message which will not actually connect, only check for existing sessions for the target and master service
// @note relaying by master services should take a slightly different path, when they receive something not for the
// master service itself, it should relay this on to all other master services, which in turn all including original
// receiver pass on to any sessions matching an identity that is part of the group, alternatively they can use a pub/sub
// like amqp to relay between the master services more efficiently than using the websocket to send every master service
// session the message individually
}
} else {
for (ks_hash_iterator_t *it = ks_hash_first(bh->transports, KS_UNLOCKED); it; it = ks_hash_next(&it)) {
......
......@@ -40,7 +40,7 @@ KS_DECLARE(ks_status_t) blade_identity_create(blade_identity_t **biP, ks_pool_t
KS_DECLARE(ks_status_t) blade_identity_destroy(blade_identity_t **biP);
KS_DECLARE(ks_status_t) blade_identity_parse(blade_identity_t *bi, const char *uri);
KS_DECLARE(const char *) blade_identity_uri(blade_identity_t *bi);
KS_DECLARE(ks_status_t) blade_identity_parameter_get(blade_identity_t *bi, const char *key, const char **value);
KS_DECLARE(const char *) blade_identity_parameter_get(blade_identity_t *bi, const char *key);
KS_END_EXTERN_C
#endif
......
......@@ -50,7 +50,7 @@ KS_DECLARE(ks_thread_pool_t *) blade_handle_tpool_get(blade_handle_t *bh);
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);
KS_DECLARE(ks_status_t) blade_handle_connect(blade_handle_t *bh, blade_connection_t **bcP, blade_identity_t *target);
KS_DECLARE(ks_bool_t) blade_handle_datastore_available(blade_handle_t *bh);
KS_DECLARE(ks_status_t) blade_handle_datastore_store(blade_handle_t *bh, const void *key, int32_t key_length, const void *data, int64_t data_length);
......
......@@ -30,12 +30,14 @@ void command_test(blade_handle_t *bh, char *args);
void command_quit(blade_handle_t *bh, char *args);
void command_store(blade_handle_t *bh, char *args);
void command_fetch(blade_handle_t *bh, char *args);
void command_connect(blade_handle_t *bh, char *args);
static const struct command_def_s command_defs[] = {
{ "test", command_test },
{ "quit", command_quit },
{ "store", command_store },
{ "fetch", command_fetch },
{ "connect", command_connect },
{ NULL, NULL }
};
......@@ -47,6 +49,8 @@ int main(int argc, char **argv)
config_setting_t *config_blade = NULL;
blade_module_t *mod_wss = NULL;
//blade_identity_t *id = NULL;
const char *cfgpath = "bladec.cfg";
ks_global_set_default_logger(KS_LOG_LEVEL_DEBUG);
......@@ -54,12 +58,10 @@ int main(int argc, char **argv)
blade_handle_create(&bh, NULL, NULL);
//blade_identity_create(&id, blade_handle_pool_get(bh));
//blade_identity_parse(id, "test@domain.com/laptop?transport=wss&host=127.0.0.1&port=1234");
if (argc > 1) cfgpath = argv[1];
// @todo load config file, and lookup "blade" setting to put into config_blade
config_init(&config);
if (!config_read_file(&config, "bladec.cfg")) {
if (!config_read_file(&config, cfgpath)) {
ks_log(KS_LOG_ERROR, "%s:%d - %s\n", config_error_file(&config), config_error_line(&config), config_error_text(&config));
config_destroy(&config);
return EXIT_FAILURE;
......@@ -91,6 +93,10 @@ int main(int argc, char **argv)
loop(bh);
blade_module_wss_on_shutdown(mod_wss);
blade_module_wss_on_unload(mod_wss);
blade_handle_destroy(&bh);
blade_shutdown();
......@@ -236,3 +242,18 @@ void command_fetch(blade_handle_t *bh, char *args)
blade_handle_datastore_fetch(bh, blade_datastore_fetch_callback, key, strlen(key), bh);
}
void command_connect(blade_handle_t *bh, char *args)
{
blade_connection_t *bc = NULL;
blade_identity_t *target = NULL;
ks_assert(bh);
ks_assert(args);
blade_identity_create(&target, blade_handle_pool_get(bh));
if (blade_identity_parse(target, args) == KS_STATUS_SUCCESS) blade_handle_connect(bh, &bc, target);
blade_identity_destroy(&target);
}
blade:
{
identity = "peer@domain";
directory:
{
uris = ( "directory@domain?transport=wss&host=127.0.0.1&port=2100" );
};
datastore:
{
database:
......@@ -12,18 +8,4 @@ blade:
path = ":mem:";
};
};
wss:
{
endpoints:
{
ipv4 = ( { address = "0.0.0.0", port = 2101 } );
ipv6 = ( { address = "::", port = 2101 } );
backlog = 128;
};
# SSL group is optional, disabled when absent
ssl:
{
# todo: server SSL stuffs here
};
};
};
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论