If the socket is non-blocking mode, while loop can make busy waiting.
To avoid busy waiting, this patch adds calling usleep() with 100 ms.
Change-Id: I41d25ee6f7c314c29920b48b00a8b94c67c6825f
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
if (fcntl(fd_, F_GETFL, 0) & O_NONBLOCK)
is_blocking = false;
+ int retry_count = 20;
unsigned char* buffer = static_cast<unsigned char*>(buf);
unsigned int left = size;
while (left) {
return -EAGAIN;
}
- continue;
+ if (retry_count > 0) {
+ usleep(100 * 1000);
+ retry_count--;
+ continue;
+ }
}
_E("recv() is failed. fd(%d), errno(%d)", fd_, errno);
ssize_t r;
size_t size = data_size;
bool is_blocking;
+ int retry_count = 20;
if (fcntl(fd, F_GETFL, 0) & O_NONBLOCK)
is_blocking = false;
return -EAGAIN;
}
- continue;
+ if (retry_count > 0) {
+ usleep(100 * 1000);
+ retry_count--;
+ continue;
+ }
}
_E("recv error. fd(%d), errno(%d)",