FS-10167: Temporary commit while trying to figure out why the release build of libsodium under VS won't link properly.

This commit is contained in:
Shane Bryldt 2017-04-21 15:42:51 -06:00
parent db7b27317a
commit a8a935d64f
6 changed files with 64 additions and 16 deletions

View File

@ -43,6 +43,8 @@ struct blade_connection_s {
blade_connection_direction_t direction;
volatile blade_connection_state_t state;
ks_cond_t *cond;
const char *id;
ks_rwl_t *lock;
@ -99,6 +101,9 @@ KS_DECLARE(ks_status_t) blade_connection_create(blade_connection_t **bcP, blade_
bc->handle = bh;
bc->pool = pool;
ks_cond_create(&bc->cond, pool);
ks_assert(bc->cond);
ks_uuid(&id);
bc->id = ks_uuid_str(pool, &id);
ks_assert(bc->id);
@ -292,13 +297,19 @@ KS_DECLARE(void) blade_connection_state_set(blade_connection_t *bc, blade_connec
ks_assert(bc);
ks_cond_lock(bc->cond);
callback = blade_connection_state_callback_lookup(bc, state);
if (callback) hook = callback(bc, BLADE_CONNECTION_STATE_CONDITION_PRE);
bc->state = state;
ks_cond_unlock(bc->cond);
if (hook == BLADE_CONNECTION_STATE_HOOK_DISCONNECT) blade_connection_disconnect(bc);
ks_cond_try_signal(bc->cond);
}
KS_DECLARE(blade_connection_state_t) blade_connection_state_get(blade_connection_t *bc)
@ -362,7 +373,12 @@ void *blade_connection_state_thread(ks_thread_t *thread, void *data)
bc = (blade_connection_t *)data;
ks_cond_lock(bc->cond);
while (!shutdown) {
// Entering the call below, the mutex is expected to be locked and will be unlocked by the call
ks_cond_timedwait(bc->cond, 100);
// Leaving the call above, the mutex will be locked after being signalled, timing out, or woken up for any reason
state = bc->state;
switch (state) {
@ -388,6 +404,7 @@ void *blade_connection_state_thread(ks_thread_t *thread, void *data)
default: break;
}
}
ks_cond_unlock(bc->cond);
blade_connection_destroy(&bc);

View File

@ -656,7 +656,7 @@ ks_status_t blade_transport_wss_on_send(blade_connection_t *bc, cJSON *json)
ks_status_t blade_transport_wss_read(blade_transport_wss_t *bt_wss, cJSON **json)
{
// @todo get exact timeout from service config?
int32_t poll_flags = ks_wait_sock(bt_wss->sock, 100, KS_POLL_READ); // | KS_POLL_ERROR);
int32_t poll_flags = ks_wait_sock(bt_wss->sock, 1, KS_POLL_READ); // | KS_POLL_ERROR);
*json = NULL;

View File

@ -42,7 +42,6 @@ struct blade_session_s {
const char *id;
ks_rwl_t *lock;
ks_mutex_t *mutex;
ks_cond_t *cond;
ks_list_t *connections;
@ -87,7 +86,6 @@ static void blade_session_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool
bs->sending = NULL;
bs->connections = NULL;
bs->cond = NULL;
bs->mutex = NULL;
bs->lock = NULL;
//ks_pool_free(bs->pool, &bs->id);
@ -122,9 +120,7 @@ KS_DECLARE(ks_status_t) blade_session_create(blade_session_t **bsP, blade_handle
ks_rwl_create(&bs->lock, pool);
ks_assert(bs->lock);
ks_mutex_create(&bs->mutex, KS_MUTEX_FLAG_DEFAULT, pool);
ks_assert(bs->mutex);
ks_cond_create_ex(&bs->cond, pool, bs->mutex);
ks_cond_create(&bs->cond, pool);
ks_assert(bs->cond);
ks_list_create(&bs->connections, pool);
@ -311,13 +307,11 @@ KS_DECLARE(void) blade_session_state_set(blade_session_t *bs, blade_session_stat
{
ks_assert(bs);
ks_mutex_lock(bs->mutex);
ks_cond_lock(bs->cond);
bs->state = state;
blade_handle_session_state_callbacks_execute(bs, BLADE_SESSION_STATE_CONDITION_PRE);
ks_cond_unlock(bs->cond);
ks_mutex_unlock(bs->mutex);
ks_cond_try_signal(bs->cond);
}
@ -469,8 +463,7 @@ void *blade_session_state_thread(ks_thread_t *thread, void *data)
bs = (blade_session_t *)data;
ks_mutex_lock(bs->mutex);
ks_cond_lock(bs->cond);
while (!shutdown) {
// Entering the call below, the mutex is expected to be locked and will be unlocked by the call
ks_cond_timedwait(bs->cond, 100);
@ -524,7 +517,7 @@ void *blade_session_state_thread(ks_thread_t *thread, void *data)
blade_session_hangup(bs);
}
}
ks_mutex_unlock(bs->mutex);
ks_cond_unlock(bs->cond);
blade_session_destroy(&bs);

View File

@ -38,6 +38,7 @@ int main(int argc, char **argv)
config_setting_t *config_blade = NULL;
const char *cfgpath = "bladec.cfg";
const char *session_state_callback_id = NULL;
const char *autoconnect = NULL;
ks_global_set_default_logger(KS_LOG_LEVEL_DEBUG);
@ -45,7 +46,8 @@ int main(int argc, char **argv)
blade_handle_create(&bh);
if (argc > 1) cfgpath = argv[1];
//if (argc > 1) cfgpath = argv[1];
if (argc > 1) autoconnect = argv[1];
config_init(&config);
if (!config_read_file(&config, cfgpath)) {
@ -72,7 +74,18 @@ int main(int argc, char **argv)
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);
if (autoconnect) {
blade_connection_t *bc = NULL;
blade_identity_t *target = NULL;
blade_identity_create(&target, blade_handle_pool_get(bh));
if (blade_identity_parse(target, autoconnect) == KS_STATUS_SUCCESS) blade_handle_connect(bh, &bc, target, NULL);
blade_identity_destroy(&target);
ks_sleep_ms(2000);
} else loop(bh);
//blade_handle_session_state_callback_unregister(bh, session_state_callback_id);
@ -197,9 +210,32 @@ void command_connect(blade_handle_t *bh, char *args)
blade_identity_destroy(&target);
}
ks_bool_t on_blade_chat_send_response(blade_response_t *bres);
ks_bool_t on_blade_chat_join_response(blade_response_t *bres) // @todo this should get userdata passed in from when the callback is registered
{
blade_session_t *bs = NULL;
cJSON *req = NULL;
cJSON *params = NULL;
ks_log(KS_LOG_DEBUG, "Received Chat Join Response!\n");
bs = blade_handle_sessions_get(bres->handle, bres->session_id);
if (!bs) {
ks_log(KS_LOG_DEBUG, "Unknown Session: %s\n", bres->session_id);
return KS_FALSE;
}
blade_rpc_request_create(blade_handle_pool_get(bres->handle), &req, &params, NULL, "blade.chat.send");
ks_assert(req);
ks_assert(params);
cJSON_AddStringToObject(params, "message", "Hello World!");
blade_session_send(bs, req, on_blade_chat_send_response);
blade_session_read_unlock(bs);
return KS_FALSE;
}

View File

@ -70,7 +70,7 @@ int main(int argc, char **argv)
blade_handle_create(&bh);
if (argc > 1) cfgpath = argv[1];
//if (argc > 1) cfgpath = argv[1];
config_init(&config);
if (!config_read_file(&config, cfgpath)) {

View File

@ -315,12 +315,14 @@
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<MinimalRebuild>false</MinimalRebuild>
<AdditionalOptions>/arch:AVX %(AdditionalOptions)</AdditionalOptions>
<SuppressStartupBanner>true</SuppressStartupBanner>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<SuppressStartupBanner>true</SuppressStartupBanner>
</Link>
</ItemDefinitionGroup>
<ItemGroup>