Retry when writing to keysound pipe is failed with 'Resource temporarily unavailable' 25/218625/1 accepted/tizen/5.5/unified/20191210.221237 submit/tizen_5.5/20191127.021040 submit/tizen_5.5/20191209.074502
authorSeungbae Shin <seungbae.shin@samsung.com>
Wed, 20 Nov 2019 04:54:48 +0000 (13:54 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Tue, 26 Nov 2019 06:31:35 +0000 (15:31 +0900)
[Version] 0.12.53
[Issue Type] Improvement

Change-Id: Ib9e43afca246832b81b8e7dc4e559d66ba13194c

mm_sound_keysound.c
packaging/libmm-sound.spec

index 9f42330..3c6c95c 100644 (file)
@@ -51,6 +51,9 @@
 #define AUDIO_VOLUME_CONFIG_TYPE(vol) (vol & 0x00FF)
 #define AUDIO_VOLUME_CONFIG_GAIN(vol) (vol & 0xFF00)
 
+#define MAX_WRITE_RETRY 50
+#define WRITE_RETRY_INTERVAL_MS 20
+
 typedef struct ipc_data {
        char filename[FILE_FULL_PATH];
        char role[ROLE_NAME_LEN];
@@ -147,6 +150,7 @@ static int _mm_sound_play_keysound(const char *filename, int volume_config, ipc_
        int ret = MM_ERROR_NONE;
        const char *role = NULL;
        const char *vol_gain_type = NULL;
+       int retry_remaining = MAX_WRITE_RETRY;
 
 #ifdef USE_LWIPC
        if (!_mm_sound_check_pa_ready()) {
@@ -158,61 +162,69 @@ static int _mm_sound_play_keysound(const char *filename, int volume_config, ipc_
        if (!filename)
                return MM_ERROR_SOUND_INVALID_FILE;
 
+       /* Check whether file exists */
+       if (access(filename, F_OK) == -1) {
+               char str_error[256];
+
+               strerror_r(errno, str_error, sizeof(str_error));
+               debug_error("file [%s] doesn't exists : [%s][%d]", filename, str_error, errno);
+
+               return MM_ERROR_SOUND_FILE_NOT_FOUND;
+       }
+
        /* convert volume type to role/volume gain */
        role = convert_volume_type_to_role(AUDIO_VOLUME_CONFIG_TYPE(volume_config));
        if (role)
                vol_gain_type = convert_volume_gain_type_to_string(AUDIO_VOLUME_CONFIG_GAIN(volume_config));
 
        if (ipc_type == IPC_TYPE_PIPE) {
-               int res = 0;
+               size_t size_to_write = sizeof(ipc_t);
+               ssize_t written = 0;
                int fd = -1;
-               int size = 0;
                ipc_t data = { { 0, }, { 0, }, { 0, } };
 
-               /* Check whether file exists */
-               fd = open(filename, O_RDONLY);
-               if (fd == -1) {
-                       char str_error[256];
-                       int errsv = errno;
-                       strerror_r(errsv, str_error, sizeof(str_error));
-                       debug_error("file open failed with [%s][%d]", str_error, errsv);
-                       switch (errsv) {
-                       case ENOENT:
-                               return MM_ERROR_SOUND_FILE_NOT_FOUND;
-                       default:
-                               return MM_ERROR_SOUND_INTERNAL;
-                       }
-               }
-               close(fd);
-               fd = -1;
-
                /* Open PIPE */
                fd = open(KEYTONE_PATH, O_WRONLY | O_NONBLOCK);
                if (fd == -1) {
-                       debug_error("Fail to open pipe");
-                       return MM_ERROR_SOUND_FILE_NOT_FOUND;
+                       char str_error[256];
+
+                       strerror_r(errno, str_error, sizeof(str_error));
+                       debug_error("Fail to open pipe: [%s][%d]", str_error, errno);
+
+                       return MM_ERROR_SOUND_INTERNAL;
                }
 
                /* convert volume type to role/volume gain */
                if (role)
                        MMSOUND_STRNCPY(data.role, role, ROLE_NAME_LEN);
-
                if (vol_gain_type)
                        MMSOUND_STRNCPY(data.volume_gain_type, vol_gain_type, VOLUME_GAIN_TYPE_LEN);
-
                MMSOUND_STRNCPY(data.filename, filename, FILE_FULL_PATH);
 
                debug_msg("filepath=[%s], role=[%s], volume_gain_type=[%s]", data.filename, data.role, data.volume_gain_type);
-               size = sizeof(ipc_t);
 
                /* Write to PIPE */
-               res = write(fd, &data, size);
-               if (res < 0) {
-                       char str_error[256];
-                       strerror_r(errno, str_error, sizeof(str_error));
-                       debug_error("Fail to write data: [%s][%d]", str_error, errno);
-                       ret = MM_ERROR_SOUND_INTERNAL;
-               }
+               do {
+                       written = write(fd, &data, size_to_write);
+                       if (written == -1) {
+                               char str_error[256];
+                               int errsv = errno;
+
+                               strerror_r(errsv, str_error, sizeof(str_error));
+                               debug_error("[%d] Fail to write, written = %zd, [%s][%d]",
+                                                       MAX_WRITE_RETRY - retry_remaining, written, str_error, errsv);
+
+                               if (errsv != EAGAIN || --retry_remaining == 0) {
+                                       ret = MM_ERROR_SOUND_INTERNAL;
+                                       break;
+                               }
+
+                               usleep(WRITE_RETRY_INTERVAL_MS * 1000);
+                       } else if (retry_remaining != MAX_WRITE_RETRY) {
+                               debug_msg("retry success!!");
+                       }
+               } while (written != size_to_write);
+
                /* Close PIPE */
                close(fd);
 
index 9762ad6..e4f1e59 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-sound
 Summary:    MMSound Package contains client lib and sound_server binary
-Version:    0.12.52
+Version:    0.12.53
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0