fd-handler: add context information 37/282237/2
authorUnsung Lee <unsung.lee@samsung.com>
Thu, 29 Sep 2022 02:48:28 +0000 (11:48 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Thu, 29 Sep 2022 02:54:11 +0000 (11:54 +0900)
Change-Id: I11f4049f4141a6c87235b7b65ab6a7a101cb2abc
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/common/fd-handler.c

index 30ae2a7..288988a 100644 (file)
@@ -34,6 +34,7 @@
 struct fd_handler_s {
        int fd;
        GIOChannel *ch;
+       GMainContext *context;
        guint id;
        fd_changed_cb changed;
        void *data;
@@ -53,8 +54,13 @@ int remove_fd_read_handler(fd_handler_h *handler)
        if (h->free_func)
                h->free_func(h->data);
 
-       if (h->id)
-               g_source_remove(h->id);
+       if (h->id) {
+               GSource *source = g_main_context_find_source_by_id(h->context, h->id);
+               if (source)
+                       g_source_destroy(source);
+               else
+                       _I("Source ID %u was not found when attempting to remove it", h->id);
+       }
 
        if (h->ch)
                g_io_channel_unref(h->ch);
@@ -151,6 +157,7 @@ int add_fd_read_handler(GMainContext *context, int fd,
        h->data = data;
        h->free_func = free_func;
        h->ch = ch;
+       h->context = context;
        h->id = id;
        h->handler_p = handler;
        if (handler != NULL)