sound-player: Read data from pipe with non-blocking mode 08/46008/3 accepted/tizen/mobile/20150819.235400 accepted/tizen/tv/20150819.235410 accepted/tizen/wearable/20150819.235429 submit/tizen/20150819.063347
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 13 Aug 2015 07:22:39 +0000 (16:22 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 19 Aug 2015 05:57:33 +0000 (14:57 +0900)
When the client request comes from pipe, it calls read function with non-blocking mode.
It leads to avoid blocking of the context even if the pipe does not work well.
Fix bug for invalid check routine of the return value.

[Version] 5.0-33
[Profile] Common
[Issue Type] Enhance codes

Change-Id: Id62ef8a2f867d21ffaf704577246b96029a67191
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/pulseaudio.spec
src/modules/module-sound-player.c

index b7d7b17..3a28e95 100644 (file)
@@ -11,7 +11,7 @@
 Name:             pulseaudio
 Summary:          Improved Linux sound server
 Version:          5.0
-Release:          32
+Release:          33
 Group:            Multimedia/Audio
 License:          GPL-2.0+ and LGPL-2.1+
 URL:              http://pulseaudio.org
index 29a4754..9f98543 100644 (file)
@@ -158,6 +158,7 @@ struct userdata {
 #define FILE_FULL_PATH 1024        /* File path length */
 #define ROLE_NAME_LEN 64                /* Role name length */
 #define VOLUME_GAIN_TYPE_LEN 64    /* Volume gain type length */
+#define RETRY_NUM 100
 
 struct ipc_data {
     char filename[FILE_FULL_PATH];
@@ -209,8 +210,9 @@ static int _simple_play(struct userdata *u, const char *file_path, const char *r
     }
 
     pa_log_debug("pa_scache_play_item() start");
-    if ((ret = pa_scache_play_item(u->module->core, name, sink, PA_VOLUME_NORM, p, &stream_idx) < 0)) {
-        pa_log_error("pa_scache_play_item fail");
+    ret = pa_scache_play_item(u->module->core, name, sink, PA_VOLUME_NORM, p, &stream_idx);
+    if (ret < 0) {
+        pa_log_error("pa_scache_play_item fail, ret[%d]", ret);
         goto exit;
     }
     pa_log_debug("pa_scache_play_item() end, stream_idx(%u)", stream_idx);
@@ -311,7 +313,6 @@ static void handle_simple_play(DBusConnection *conn, DBusMessage *msg, void *use
         *stream_idx = result;
         pa_idxset_put(u->stream_idxs, stream_idx, &idx);
     }
-
     pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_INT32, &result);
 }
 
@@ -437,6 +438,9 @@ static int init_ipc (struct userdata *u) {
         goto fail;
     }
 
+    /* for non-blocking read */
+    fcntl(u->fd, F_SETFL, O_NONBLOCK);
+
     /* change access mode so group can use keytone pipe */
     if (fchmod (u->fd, 0666) == -1)
         pa_log_warn("Changing keytone access mode is failed. errno=[%d][%s]", errno, strerror(errno));
@@ -509,7 +513,9 @@ static void io_event_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io
     struct userdata *u = userdata;
     struct ipc_data data;
     int ret = 0;
-    int size = 0;
+    int data_size = 0;
+    int read_sum = 0;
+    int retry_count = 0;
 
     pa_assert(io);
     pa_assert(u);
@@ -520,15 +526,20 @@ static void io_event_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io
     }
 
     if (events & PA_IO_EVENT_INPUT) {
-        size = sizeof(data);
-        memset(&data, 0, size);
-        ret = read(fd, (void *)&data, size);
-        if(ret != -1) {
+        data_size = sizeof(data);
+        memset(&data, 0, data_size);
+        while (read_sum != data_size && retry_count < RETRY_NUM) {
+            ret = read(fd, ((void *)&data)+read_sum, data_size-read_sum);
+            if (ret < 0 && errno == EAGAIN)
+                retry_count++;
+            else
+                read_sum += ret;
+        }
+        if (read_sum == data_size) {
             pa_log_info("name(%s), role(%s), volume_gain_type(%s)", data.filename, data.role, data.volume_gain_type);
             _simple_play(u, data.filename, data.role, data.volume_gain_type);
-
         } else {
-            pa_log_warn("Fail to read file");
+            pa_log_warn("Fail to read, retry_count(%d), read sum(%d), err(%s)", retry_count, read_sum, pa_cstrerror(errno));
         }
     }