#define LOG_TAG "RPC_PORT"
-#define MAX_RETRY_CNT 18
+#define MAX_RETRY_CNT 100
#define SEND_TIMEOUT 500
+#define MAX_SLEEP 100 * 1000 * 1000
+#define MIN_SLEEP 5 * 1000 * 1000
namespace rpc_port {
namespace internal {
unsigned int left = size;
ssize_t nb;
int retry_cnt = 0;
- struct timespec TRY_SLEEP_TIME = { 0, 5 * 1000 * 1000 };
+ struct timespec TRY_SLEEP_TIME = { 0, MIN_SLEEP };
int bytes_read = 0;
char* buffer = static_cast<char*>(buf);
std::lock_guard<std::recursive_mutex> lock(mutex_);
retry_cnt++;
nanosleep(&TRY_SLEEP_TIME, 0);
TRY_SLEEP_TIME.tv_nsec *= 2;
- if (TRY_SLEEP_TIME.tv_nsec > 999999999)
- TRY_SLEEP_TIME.tv_nsec = 999999999;
+ if (TRY_SLEEP_TIME.tv_nsec > MAX_SLEEP)
+ TRY_SLEEP_TIME.tv_nsec = MAX_SLEEP;
continue;
}
+
LOGE("read_socket: ...error fd %d: errno %d\n", fd_, errno);
- return RPC_PORT_ERROR_IO_ERROR;
+ return RPC_PORT_ERROR_IO_ERROR;
}
left -= nb;
buffer += nb;
bytes_read += nb;
retry_cnt = 0;
+ TRY_SLEEP_TIME.tv_nsec = MIN_SLEEP;
}
if (left != 0) {
unsigned int left = size;
ssize_t nb;
int retry_cnt = 0;
+ struct timespec TRY_SLEEP_TIME = { 0, MIN_SLEEP };
struct pollfd fds[1];
int ret;
int bytes_write = 0;
while (left && (retry_cnt < MAX_RETRY_CNT)) {
nb = write(fd_, buffer, left);
if (nb == -1) {
- if (errno == EINTR) {
- LOGE("write_socket: EINTR error continue ...");
+ if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) {
+ LOGE("write_socket: %d errno, sleep and retry ...", errno);
retry_cnt++;
+ nanosleep(&TRY_SLEEP_TIME, 0);
+ TRY_SLEEP_TIME.tv_nsec *= 2;
+ if (TRY_SLEEP_TIME.tv_nsec > MAX_SLEEP)
+ TRY_SLEEP_TIME.tv_nsec = MAX_SLEEP;
continue;
}
buffer += nb;
bytes_write += nb;
retry_cnt = 0;
+ TRY_SLEEP_TIME.tv_nsec = MIN_SLEEP;
}
if (left != 0) {