sensord: add the checking EAGAIN while the data is sent by socket 64/64864/2
authorkibak.yoon <kibak.yoon@samsung.com>
Tue, 5 Apr 2016 05:25:49 +0000 (14:25 +0900)
committerkibak.yoon <kibak.yoon@samsung.com>
Wed, 6 Apr 2016 03:05:36 +0000 (12:05 +0900)
If socket is not available to use it temporarily,
EAGAIN(EWOULDBLOCK) is returned by ::send().
so in order to prevent that data are omitted, retry to send it.

Change-Id: I4b8bcf1fefa1b20e820ec127d24b2e61f6253edf
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
src/shared/csocket.cpp

index 199a722..6aa33b6 100644 (file)
@@ -216,6 +216,16 @@ ssize_t csocket::send_for_stream(const void *buffer, size_t size) const
                                m_sock_fd, buffer, total_sent_size, size, total_sent_size,
                                len, get_client_name());
 
+                       /*
+                       * If socket is not available to use it temporarily,
+                       * EAGAIN(EWOULDBLOCK) is returned by ::send().
+                       * so in order to prevent that data are omitted, retry to send it
+                       */
+                       if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
+                               usleep(1000);
+                               continue;
+                       }
+
                        if (errno != EINTR) {
                                err = errno;
                                break;
@@ -247,6 +257,16 @@ ssize_t csocket::recv_for_stream(void* buffer, size_t size) const
                                m_sock_fd, buffer, total_recv_size, size, total_recv_size,
                                len, get_client_name());
 
+                       /*
+                       * If socket is not available to use during for some time,
+                       * EAGAIN(EWOULDBLOCK) is returned by ::recv().
+                       * so in order to prevent that data are omitted, retry to receive it
+                       */
+                       if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
+                               usleep(1000);
+                               continue;
+                       }
+
                        if (errno != EINTR) {
                                err = errno;
                                break;