libgnunetchat

library for GNUnet Messenger
Log | Files | Refs | README | LICENSE

commit 76691d10ca25fda6938a02211a9fde538ed111ac
parent 638df3525e10f8e116c13ab9b078e0f25e286036
Author: Jacki <jacki@thejackimonster.de>
Date:   Sun,  5 May 2024 18:23:13 +0200

Make connect function call always asynchronous

Signed-off-by: Jacki <jacki@thejackimonster.de>

Diffstat:
Msrc/gnunet_chat_handle.c | 12++++++------
Msrc/gnunet_chat_handle.h | 2+-
Msrc/gnunet_chat_lib.c | 32+++++++++++++++++++++++++-------
Msrc/gnunet_chat_lib_intern.c | 20+++++++++++++++++++-
4 files changed, 51 insertions(+), 15 deletions(-)

diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c @@ -187,15 +187,15 @@ handle_destroy (struct GNUNET_CHAT_Handle *handle) GNUNET_SCHEDULER_cancel(handle->shutdown_hook); if (handle->destruction) GNUNET_SCHEDULER_cancel(handle->destruction); - if (handle->disconnection) - GNUNET_SCHEDULER_cancel(handle->disconnection); + if (handle->connection) + GNUNET_SCHEDULER_cancel(handle->connection); if (handle->refresh) GNUNET_SCHEDULER_cancel(handle->refresh); if (handle->monitor) GNUNET_NAMESTORE_zone_monitor_stop(handle->monitor); - handle->disconnection = NULL; + handle->connection = NULL; if (handle->current) handle_disconnect(handle); @@ -479,11 +479,11 @@ handle_disconnect (struct GNUNET_CHAT_Handle *handle) handle->contacts = NULL; handle->groups = NULL; - if (handle->disconnection) - GNUNET_SCHEDULER_cancel(handle->disconnection); + if (handle->connection) + GNUNET_SCHEDULER_cancel(handle->connection); handle->current = NULL; - handle->disconnection = NULL; + handle->connection = NULL; handle_update_key(handle); } diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h @@ -87,7 +87,7 @@ struct GNUNET_CHAT_Handle const struct GNUNET_CONFIGURATION_Handle* cfg; struct GNUNET_SCHEDULER_Task *shutdown_hook; struct GNUNET_SCHEDULER_Task *destruction; - struct GNUNET_SCHEDULER_Task *disconnection; + struct GNUNET_SCHEDULER_Task *connection; struct GNUNET_SCHEDULER_Task *refresh; struct GNUNET_CHAT_InternalServices *services_head; diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c @@ -167,20 +167,29 @@ GNUNET_CHAT_connect (struct GNUNET_CHAT_Handle *handle, if ((!handle) || (handle->destruction)) return; + if (handle->connection) + GNUNET_SCHEDULER_cancel(handle->connection); + if (handle->current == account) + { + handle->next = NULL; + handle->connection = NULL; return; + } if (handle->current) { handle->next = account; + handle->connection = NULL; GNUNET_CHAT_disconnect(handle); return; } - if (!account) - return; - - handle_connect(handle, account); + handle->next = account; + handle->connection = GNUNET_SCHEDULER_add_now( + task_handle_connection, + handle + ); } @@ -189,11 +198,20 @@ GNUNET_CHAT_disconnect (struct GNUNET_CHAT_Handle *handle) { GNUNET_CHAT_VERSION_ASSERT(); - if ((!handle) || (handle->destruction) || - (!(handle->current)) || (handle->disconnection)) + if ((!handle) || (handle->destruction)) return; + + if (handle->connection) + GNUNET_SCHEDULER_cancel(handle->connection); + + if (!(handle->current)) + { + handle->next = NULL; + handle->connection = NULL; + return; + } - handle->disconnection = GNUNET_SCHEDULER_add_now( + handle->connection = GNUNET_SCHEDULER_add_now( task_handle_disconnection, handle ); diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c @@ -71,13 +71,31 @@ task_handle_destruction (void *cls) } void +task_handle_connection (void *cls) +{ + GNUNET_assert(cls); + + struct GNUNET_CHAT_Handle *handle = (struct GNUNET_CHAT_Handle*) cls; + + handle->connection = NULL; + + if (! handle->next) + return; + + const struct GNUNET_CHAT_Account *account = handle->next; + handle->next = NULL; + + handle_connect(handle, account); +} + +void task_handle_disconnection (void *cls) { GNUNET_assert(cls); struct GNUNET_CHAT_Handle *handle = (struct GNUNET_CHAT_Handle*) cls; - handle->disconnection = NULL; + handle->connection = NULL; handle_disconnect(handle); if (! handle->next)