If the socket is non-blocking mode, while loop can make busy wating
To avoid busy wating, this patch adds calling usleep() with 100 ms
Change-Id: Id4c17e2f8e403ebfe17ae903fa1f4ccb86822c58
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
int AbstractSocket::ReceiveData(void* buf, unsigned int size) {
bool is_blocking = true;
+ int retry_count = 20;
if (fcntl(fd_, F_GETFL, 0) & O_NONBLOCK)
is_blocking = false;
return -errno;
}
- continue;
+ if (retry_count > 0) {
+ LOG(WARNING) << "Fail to receive data from "
+ << "non-blocking socket retry count : " << retry_count
+ << " left byte : " << left << " receive byte : " << recv_byte;
+ usleep(100 * 1000);
+ retry_count--;
+ continue;
+ }
}
LOG(ERROR) << "recv() is failed. fd: " << fd_ << ", errno: " << errno;