Do not retry receiving failed mime type data 34/312534/1
authorJunkyeong Kim <jk0430.kim@samsung.com>
Tue, 11 Jun 2024 09:05:35 +0000 (18:05 +0900)
committerJunkyeong Kim <jk0430.kim@samsung.com>
Tue, 11 Jun 2024 09:05:40 +0000 (18:05 +0900)
erase offered mime type from list if data receiving failed.

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

index f9949c3..b2b22c6 100644 (file)
@@ -137,7 +137,7 @@ _cbhm_add_mime_type(Cbhm_Data_Offer *cbhm_data_offer, const char *type)
                }
        }
 }
-#if 0
+
 static void
 _cbhm_remove_mime_type(Cbhm_Data_Offer *cbhm_data_offer, const char *type)
 {
@@ -155,11 +155,12 @@ _cbhm_remove_mime_type(Cbhm_Data_Offer *cbhm_data_offer, const char *type)
                        LIST_DEL(&mime->item_link);
                        free(mime);
                        DBG("[CBHM]_cbhm_remove_mime_type: remove mime type : %s\n", type);
+                       cbhm_data_offer->type_count--;
                        break;
                }
        }
 }
-#endif
+
 static void
 _cbhm_free_mime_type_list(Cbhm_Data_Offer *cbhm_data_offer)
 {
@@ -417,6 +418,7 @@ _cbhm_receive_data(Cbhm_Glib_Info *info)
        char buffer[255];
        int len, old_len, retry_cnt = 0;
        void *data;
+       bool pipe_failed = false;
 
        if (!info) return;
        if (!info->data_device_mgr) return;
@@ -433,10 +435,18 @@ _cbhm_receive_data(Cbhm_Glib_Info *info)
                len = read(info->datafd.fd, buffer, sizeof(buffer));
                if (len == -1) {
                        if (errno == EINTR || errno == EAGAIN) {
+                               retry_cnt++;
+                               if (retry_cnt > PIPE_RETRY_MAX) {
+                                       ERR("[CBHM] read fail. retry_cnt over %d. break (%d) %m\n", PIPE_RETRY_MAX, errno);
+                                       free(received_data);
+                                       pipe_failed = true;
+                                       goto receive_data_done;
+                               }
                                continue;
                        } else {
                                ERR("[CBHM]_cbhm_receive_data: read fail.(%d) %m\n", errno);
                                free(received_data);
+                               pipe_failed = true;
                                goto receive_data_done;
                        }
                } else if (len == 0) {
@@ -498,6 +508,9 @@ receive_data_done:
        close(info->datafd.fd);
        info->datafd.fd = -1;
 
+       if (pipe_failed)
+               _cbhm_remove_mime_type(info->cbhm_data_offer, info->temp_mime_type);
+
        free(info->temp_mime_type);
        info->temp_mime_type = NULL;