Change data receive end condition 37/300637/3
authorJunkyeong Kim <jk0430.kim@samsung.com>
Mon, 30 Oct 2023 10:08:00 +0000 (19:08 +0900)
committerJunkyeong Kim <jk0430.kim@samsung.com>
Wed, 1 Nov 2023 04:28:04 +0000 (13:28 +0900)
Read until get EOF('\0').

Change-Id: Ia8b53da2093c2ce10c1f0e3315403bd5b2787e3f
Signed-off-by: Junkyeong Kim <jk0430.kim@samsung.com>
src/cbhm.c

index d578769..a1e8568 100644 (file)
@@ -31,6 +31,7 @@
 #include "cbhm_log.h"
 
 #define MIMETYPE_MAX 255
+#define PIPE_RETRY_MAX 2000
 
 typedef struct {
        char *mimetype;
@@ -333,7 +334,7 @@ _cbhm_receive_data(Cbhm_Glib_Info *info)
 {
        Cbhm_Received_Data *received_data;
        char buffer[255];
-       int len, old_len;
+       int len, old_len, retry_cnt = 0;
        void *data;
 
        if (!info) return;
@@ -352,15 +353,21 @@ _cbhm_receive_data(Cbhm_Glib_Info *info)
                        if (errno == EINTR || errno == EAGAIN) {
                                continue;
                        } else {
-                               ERR("[CBHM]_cbhm_receive_data: read fail. %m\n");
+                               ERR("[CBHM]_cbhm_receive_data: read fail.(%d) %m\n", errno);
                                _cbhm_free_received_data(received_data);
                                info->received_data = NULL;
                                goto receive_data_done;
                        }
+               } else if (len == 0) {
+                       retry_cnt++;
+                       if (retry_cnt > PIPE_RETRY_MAX) {
+                               ERR("[CBHM] read 0. retry_cnt over %d. break (received:%d)\n", PIPE_RETRY_MAX, received_data->len);
+                               break;
+                       }
+                       continue;
+               }
 
-               } else if (len == 0)
-                       break;
-
+               retry_cnt = 0;
                old_len = received_data->len;
 
                received_data->len += len;
@@ -377,7 +384,8 @@ _cbhm_receive_data(Cbhm_Glib_Info *info)
                        goto receive_data_done;
                }
 
-               if (len < 255) break;
+               if (buffer[len - 1] == '\0')
+                       break;
        }
 
        memcpy(buffer, ((char *)received_data->data) + received_data->len - 1, 1);