From: kibak.yoon Date: Tue, 5 Apr 2016 05:25:49 +0000 (+0900) Subject: sensord: add the checking EAGAIN while the data is sent by socket X-Git-Tag: accepted/tizen/common/20160408.185536^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0255f9dbb6d41c174c0a745d84fca2242b3e4619;p=platform%2Fcore%2Fsystem%2Fsensord.git 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 --- 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;