From 0255f9dbb6d41c174c0a745d84fca2242b3e4619 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Tue, 5 Apr 2016 14:25:49 +0900 Subject: [PATCH] sensord: add the checking EAGAIN while the data is sent by socket 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 --- src/shared/csocket.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/shared/csocket.cpp b/src/shared/csocket.cpp index 199a722..6aa33b6 100644 --- a/src/shared/csocket.cpp +++ b/src/shared/csocket.cpp @@ -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; -- 2.7.4