diff options
Diffstat (limited to 'src/chat/messenger.c')
-rw-r--r-- | src/chat/messenger.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/chat/messenger.c b/src/chat/messenger.c index 6164674..0015f25 100644 --- a/src/chat/messenger.c +++ b/src/chat/messenger.c | |||
@@ -51,6 +51,7 @@ _chat_messenger_quit(void *cls) | |||
51 | if (received < 0) | 51 | if (received < 0) |
52 | signal = MESSENGER_FAIL; | 52 | signal = MESSENGER_FAIL; |
53 | 53 | ||
54 | // Free contact infos | ||
54 | GNUNET_CHAT_iterate_contacts( | 55 | GNUNET_CHAT_iterate_contacts( |
55 | app->chat.messenger.handle, | 56 | app->chat.messenger.handle, |
56 | _chat_messenger_destroy_contacts, | 57 | _chat_messenger_destroy_contacts, |
@@ -68,6 +69,8 @@ _chat_messenger_idle(void *cls) | |||
68 | { | 69 | { |
69 | MESSENGER_Application *app = (MESSENGER_Application*) cls; | 70 | MESSENGER_Application *app = (MESSENGER_Application*) cls; |
70 | 71 | ||
72 | // Idling until the application shuts down | ||
73 | // (required to get events immediately). | ||
71 | app->chat.messenger.idle = GNUNET_SCHEDULER_add_delayed_with_priority( | 74 | app->chat.messenger.idle = GNUNET_SCHEDULER_add_delayed_with_priority( |
72 | GNUNET_TIME_relative_get_second_(), | 75 | GNUNET_TIME_relative_get_second_(), |
73 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 76 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
@@ -82,8 +85,11 @@ _chat_messenger_message(void *cls, | |||
82 | const struct GNUNET_CHAT_Message *message) | 85 | const struct GNUNET_CHAT_Message *message) |
83 | { | 86 | { |
84 | MESSENGER_Application *app = (MESSENGER_Application*) cls; | 87 | MESSENGER_Application *app = (MESSENGER_Application*) cls; |
88 | |||
89 | // Locking the mutex for synchronization | ||
85 | pthread_mutex_lock(&(app->chat.mutex)); | 90 | pthread_mutex_lock(&(app->chat.mutex)); |
86 | 91 | ||
92 | // Handle each kind of message as proper event regarding context | ||
87 | switch (GNUNET_CHAT_message_get_kind(message)) | 93 | switch (GNUNET_CHAT_message_get_kind(message)) |
88 | { | 94 | { |
89 | case GNUNET_CHAT_KIND_WARNING: | 95 | case GNUNET_CHAT_KIND_WARNING: |
@@ -186,12 +192,14 @@ chat_messenger_run(void *cls, | |||
186 | { | 192 | { |
187 | MESSENGER_Application *app = (MESSENGER_Application*) cls; | 193 | MESSENGER_Application *app = (MESSENGER_Application*) cls; |
188 | 194 | ||
195 | // Start libgnunetchat handle | ||
189 | app->chat.messenger.handle = GNUNET_CHAT_start( | 196 | app->chat.messenger.handle = GNUNET_CHAT_start( |
190 | cfg, | 197 | cfg, |
191 | &_chat_messenger_message, | 198 | &_chat_messenger_message, |
192 | app | 199 | app |
193 | ); | 200 | ); |
194 | 201 | ||
202 | // Setup pipe to handle closing the application from the other thread | ||
195 | struct GNUNET_NETWORK_FDSet *fd = GNUNET_NETWORK_fdset_create (); | 203 | struct GNUNET_NETWORK_FDSet *fd = GNUNET_NETWORK_fdset_create (); |
196 | GNUNET_NETWORK_fdset_set_native(fd, app->chat.pipe[0]); | 204 | GNUNET_NETWORK_fdset_set_native(fd, app->chat.pipe[0]); |
197 | 205 | ||
@@ -204,6 +212,8 @@ chat_messenger_run(void *cls, | |||
204 | app | 212 | app |
205 | ); | 213 | ); |
206 | 214 | ||
215 | // The idle callback seems to be necessary to not wait too long for | ||
216 | // other events | ||
207 | app->chat.messenger.idle = GNUNET_SCHEDULER_add_now( | 217 | app->chat.messenger.idle = GNUNET_SCHEDULER_add_now( |
208 | &_chat_messenger_idle, | 218 | &_chat_messenger_idle, |
209 | app | 219 | app |