Add pipe writing retry count limit 30/312530/1
authorJunkyeong Kim <jk0430.kim@samsung.com>
Tue, 11 Jun 2024 07:51:14 +0000 (16:51 +0900)
committerJunkyeong Kim <jk0430.kim@samsung.com>
Tue, 11 Jun 2024 07:51:22 +0000 (16:51 +0900)
Change-Id: I0453c5f133961cd8606a3dd9894f486e68903407

src/cbhm.c

index 4e46a60..f9949c3 100644 (file)
@@ -205,7 +205,7 @@ _data_source_send(void *data, struct wl_data_source *source, const char *mime_ty
        Cbhm_Glib_Info *info = data;
        Cbhm_Data_Offer *cbhm_data_offer;
        char *buf = NULL, *cur_buf;
-       int ret, len_remained, size_ret, len_written = 0;
+       int ret, len_remained, size_ret, len_written = 0, retry_cnt = 0;
        Cbhm_Received_Data *received_data;
 
        if (!info) return;
@@ -247,12 +247,27 @@ _data_source_send(void *data, struct wl_data_source *source, const char *mime_ty
                ret = write(fd, cur_buf, len_remained);
                if (ret == -1) {
                        if (errno == EINTR || errno == EAGAIN) {
+                               retry_cnt++;
+                               if (retry_cnt > PIPE_RETRY_MAX) {
+                                       ERR("[CBHM] write fail. retry_cnt over %d. break (%d) %m\n", PIPE_RETRY_MAX, errno);
+                                       break;
+                               }
                                continue;
                        } else {
                                ERR("[CBHM]_data_source_send : write fail.(%d) %m\n", errno);
                                break;
                        }
                }
+               else if (ret == 0) {
+                       retry_cnt++;
+                       if (retry_cnt > PIPE_RETRY_MAX) {
+                               ERR("[CBHM] write 0. retry_cnt over %d. break\n", PIPE_RETRY_MAX);
+                               break;
+                       }
+                       continue;
+               }
+
+               retry_cnt = 0;
                cur_buf += ret;
                len_written += ret;
                len_remained -= ret;