Support the finalize the connection even if it is in the recv callback
authorSung-jae Park <nicesj.park@samsung.com>
Thu, 18 Jul 2013 07:07:01 +0000 (16:07 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Thu, 18 Jul 2013 08:54:37 +0000 (17:54 +0900)
While in the recv callback, if the client tries to disconnect from the server,
the recv callback called again. because of disconnected event callback.

This patch will prevent call the same recv callback if it is in process.

Change-Id: Ib9a14849e0ff60ee72770d540bce31ac2c0cc396

packaging/libcom-core.spec
src/com-core_packet.c

index 94a9be9..3e49cc3 100644 (file)
@@ -1,6 +1,6 @@
 Name: libcom-core
 Summary: Library for the light-weight IPC 
-Version: 0.4.3
+Version: 0.4.4
 Release: 1
 Group: HomeTF/Framework
 License: Apache License
index a50ae71..a50955a 100644 (file)
@@ -76,6 +76,8 @@ struct request_ctx {
        struct packet *packet;
        int (*recv_cb)(pid_t pid, int handle, const struct packet *packet, void *data);
        void *data;
+
+       int in_recv;
 };
 
 struct recv_ctx {
@@ -128,6 +130,7 @@ static inline struct request_ctx *create_request_ctx(int handle)
        ctx->packet = NULL;
        ctx->recv_cb = NULL;
        ctx->data = NULL;
+       ctx->in_recv = 0;
 
        s_info.request_list = dlist_append(s_info.request_list, ctx);
        return ctx;
@@ -193,8 +196,11 @@ static inline int packet_ready(int handle, const struct recv_ctx *receive, struc
                        break;
                }
 
-               if (request->recv_cb)
+               if (request->recv_cb) {
+                       request->in_recv = 1;
                        request->recv_cb(receive->pid, handle, receive->packet, request->data);
+                       request->in_recv = 0;
+               }
 
                destroy_request_ctx(request);
                break;
@@ -244,12 +250,11 @@ static int client_disconnected_cb(int handle, void *data)
        struct dlist *l;
        struct dlist *n;
        pid_t pid = (pid_t)-1;
+       int referred = 0;
 
        receive = find_recv_ctx(handle);
-       if (receive) {
+       if (receive)
                pid = receive->pid;
-               destroy_recv_ctx(receive);
-       }
 
        DbgPrint("Clean up all requests and a receive context for handle(%d) for pid(%d)\n", handle, pid);
 
@@ -257,12 +262,20 @@ static int client_disconnected_cb(int handle, void *data)
                if (request->handle != handle)
                        continue;
 
+               if (request->in_recv) {
+                       referred = 1;
+                       continue;
+               }
+
                if (request->recv_cb)
                        request->recv_cb(pid, handle, NULL, request->data);
 
                destroy_request_ctx(request);
        }
 
+       if (receive && !referred)
+               destroy_recv_ctx(receive);
+
        return 0;
 }