diff options
author | Jacki <jacki@thejackimonster.de> | 2024-05-05 18:23:13 +0200 |
---|---|---|
committer | Jacki <jacki@thejackimonster.de> | 2024-05-05 18:23:13 +0200 |
commit | 76691d10ca25fda6938a02211a9fde538ed111ac (patch) | |
tree | 27ec8d67e9939d389ac20a7dd235336804f38226 | |
parent | 638df3525e10f8e116c13ab9b078e0f25e286036 (diff) | |
download | libgnunetchat-76691d10ca25fda6938a02211a9fde538ed111ac.tar.gz libgnunetchat-76691d10ca25fda6938a02211a9fde538ed111ac.zip |
Make connect function call always asynchronous
Signed-off-by: Jacki <jacki@thejackimonster.de>
-rw-r--r-- | src/gnunet_chat_handle.c | 12 | ||||
-rw-r--r-- | src/gnunet_chat_handle.h | 2 | ||||
-rw-r--r-- | src/gnunet_chat_lib.c | 32 | ||||
-rw-r--r-- | src/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 index 316b0f3..8c59f7a 100644 --- a/src/gnunet_chat_handle.c +++ b/src/gnunet_chat_handle.c | |||
@@ -187,15 +187,15 @@ handle_destroy (struct GNUNET_CHAT_Handle *handle) | |||
187 | GNUNET_SCHEDULER_cancel(handle->shutdown_hook); | 187 | GNUNET_SCHEDULER_cancel(handle->shutdown_hook); |
188 | if (handle->destruction) | 188 | if (handle->destruction) |
189 | GNUNET_SCHEDULER_cancel(handle->destruction); | 189 | GNUNET_SCHEDULER_cancel(handle->destruction); |
190 | if (handle->disconnection) | 190 | if (handle->connection) |
191 | GNUNET_SCHEDULER_cancel(handle->disconnection); | 191 | GNUNET_SCHEDULER_cancel(handle->connection); |
192 | if (handle->refresh) | 192 | if (handle->refresh) |
193 | GNUNET_SCHEDULER_cancel(handle->refresh); | 193 | GNUNET_SCHEDULER_cancel(handle->refresh); |
194 | 194 | ||
195 | if (handle->monitor) | 195 | if (handle->monitor) |
196 | GNUNET_NAMESTORE_zone_monitor_stop(handle->monitor); | 196 | GNUNET_NAMESTORE_zone_monitor_stop(handle->monitor); |
197 | 197 | ||
198 | handle->disconnection = NULL; | 198 | handle->connection = NULL; |
199 | 199 | ||
200 | if (handle->current) | 200 | if (handle->current) |
201 | handle_disconnect(handle); | 201 | handle_disconnect(handle); |
@@ -479,11 +479,11 @@ handle_disconnect (struct GNUNET_CHAT_Handle *handle) | |||
479 | handle->contacts = NULL; | 479 | handle->contacts = NULL; |
480 | handle->groups = NULL; | 480 | handle->groups = NULL; |
481 | 481 | ||
482 | if (handle->disconnection) | 482 | if (handle->connection) |
483 | GNUNET_SCHEDULER_cancel(handle->disconnection); | 483 | GNUNET_SCHEDULER_cancel(handle->connection); |
484 | 484 | ||
485 | handle->current = NULL; | 485 | handle->current = NULL; |
486 | handle->disconnection = NULL; | 486 | handle->connection = NULL; |
487 | 487 | ||
488 | handle_update_key(handle); | 488 | handle_update_key(handle); |
489 | } | 489 | } |
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h index 59ae3cf..4874230 100644 --- a/src/gnunet_chat_handle.h +++ b/src/gnunet_chat_handle.h | |||
@@ -87,7 +87,7 @@ struct GNUNET_CHAT_Handle | |||
87 | const struct GNUNET_CONFIGURATION_Handle* cfg; | 87 | const struct GNUNET_CONFIGURATION_Handle* cfg; |
88 | struct GNUNET_SCHEDULER_Task *shutdown_hook; | 88 | struct GNUNET_SCHEDULER_Task *shutdown_hook; |
89 | struct GNUNET_SCHEDULER_Task *destruction; | 89 | struct GNUNET_SCHEDULER_Task *destruction; |
90 | struct GNUNET_SCHEDULER_Task *disconnection; | 90 | struct GNUNET_SCHEDULER_Task *connection; |
91 | struct GNUNET_SCHEDULER_Task *refresh; | 91 | struct GNUNET_SCHEDULER_Task *refresh; |
92 | 92 | ||
93 | struct GNUNET_CHAT_InternalServices *services_head; | 93 | struct GNUNET_CHAT_InternalServices *services_head; |
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c index 930a7e3..ee7d4a5 100644 --- a/src/gnunet_chat_lib.c +++ b/src/gnunet_chat_lib.c | |||
@@ -167,20 +167,29 @@ GNUNET_CHAT_connect (struct GNUNET_CHAT_Handle *handle, | |||
167 | if ((!handle) || (handle->destruction)) | 167 | if ((!handle) || (handle->destruction)) |
168 | return; | 168 | return; |
169 | 169 | ||
170 | if (handle->connection) | ||
171 | GNUNET_SCHEDULER_cancel(handle->connection); | ||
172 | |||
170 | if (handle->current == account) | 173 | if (handle->current == account) |
174 | { | ||
175 | handle->next = NULL; | ||
176 | handle->connection = NULL; | ||
171 | return; | 177 | return; |
178 | } | ||
172 | 179 | ||
173 | if (handle->current) | 180 | if (handle->current) |
174 | { | 181 | { |
175 | handle->next = account; | 182 | handle->next = account; |
183 | handle->connection = NULL; | ||
176 | GNUNET_CHAT_disconnect(handle); | 184 | GNUNET_CHAT_disconnect(handle); |
177 | return; | 185 | return; |
178 | } | 186 | } |
179 | 187 | ||
180 | if (!account) | 188 | handle->next = account; |
181 | return; | 189 | handle->connection = GNUNET_SCHEDULER_add_now( |
182 | 190 | task_handle_connection, | |
183 | handle_connect(handle, account); | 191 | handle |
192 | ); | ||
184 | } | 193 | } |
185 | 194 | ||
186 | 195 | ||
@@ -189,11 +198,20 @@ GNUNET_CHAT_disconnect (struct GNUNET_CHAT_Handle *handle) | |||
189 | { | 198 | { |
190 | GNUNET_CHAT_VERSION_ASSERT(); | 199 | GNUNET_CHAT_VERSION_ASSERT(); |
191 | 200 | ||
192 | if ((!handle) || (handle->destruction) || | 201 | if ((!handle) || (handle->destruction)) |
193 | (!(handle->current)) || (handle->disconnection)) | ||
194 | return; | 202 | return; |
203 | |||
204 | if (handle->connection) | ||
205 | GNUNET_SCHEDULER_cancel(handle->connection); | ||
206 | |||
207 | if (!(handle->current)) | ||
208 | { | ||
209 | handle->next = NULL; | ||
210 | handle->connection = NULL; | ||
211 | return; | ||
212 | } | ||
195 | 213 | ||
196 | handle->disconnection = GNUNET_SCHEDULER_add_now( | 214 | handle->connection = GNUNET_SCHEDULER_add_now( |
197 | task_handle_disconnection, | 215 | task_handle_disconnection, |
198 | handle | 216 | handle |
199 | ); | 217 | ); |
diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c index c581e6e..90d35db 100644 --- a/src/gnunet_chat_lib_intern.c +++ b/src/gnunet_chat_lib_intern.c | |||
@@ -71,13 +71,31 @@ task_handle_destruction (void *cls) | |||
71 | } | 71 | } |
72 | 72 | ||
73 | void | 73 | void |
74 | task_handle_connection (void *cls) | ||
75 | { | ||
76 | GNUNET_assert(cls); | ||
77 | |||
78 | struct GNUNET_CHAT_Handle *handle = (struct GNUNET_CHAT_Handle*) cls; | ||
79 | |||
80 | handle->connection = NULL; | ||
81 | |||
82 | if (! handle->next) | ||
83 | return; | ||
84 | |||
85 | const struct GNUNET_CHAT_Account *account = handle->next; | ||
86 | handle->next = NULL; | ||
87 | |||
88 | handle_connect(handle, account); | ||
89 | } | ||
90 | |||
91 | void | ||
74 | task_handle_disconnection (void *cls) | 92 | task_handle_disconnection (void *cls) |
75 | { | 93 | { |
76 | GNUNET_assert(cls); | 94 | GNUNET_assert(cls); |
77 | 95 | ||
78 | struct GNUNET_CHAT_Handle *handle = (struct GNUNET_CHAT_Handle*) cls; | 96 | struct GNUNET_CHAT_Handle *handle = (struct GNUNET_CHAT_Handle*) cls; |
79 | 97 | ||
80 | handle->disconnection = NULL; | 98 | handle->connection = NULL; |
81 | handle_disconnect(handle); | 99 | handle_disconnect(handle); |
82 | 100 | ||
83 | if (! handle->next) | 101 | if (! handle->next) |