#define MAX_ARRAY_LEN 65535
#define PIMS_WAIT_MSEC 4500
+#define PIMS_RECVWAIT_MSEC 5000
static int _get_pid(int fd)
{
int diff_msec = _sub_timespec_in_msec(&st);
if (PIMS_WAIT_MSEC < diff_msec) {
ERR("EAGAIN error. send retry: errno[%d]", errno);
- DBG("send timestamp (%ld.%ld)sec and wait (%d)msec", st.tv_sec, st.tv_nsec, diff_msec);
+ ERR("send timestamp (%ld.%ld)sec and wait (%d)msec", st.tv_sec, st.tv_nsec, diff_msec);
int pid = _get_pid(fd);
if (true == _is_send_block(fd)) {
DBG("send blocked. kill fd(%d) pid(%d)", fd, pid);
RETV_IF(NULL == *buf, -1);
+ bool retry = false;
+ struct timespec st = {0};
+
while (length > 0) {
read_len = read(fd, (void *)temp, length);
if (read_len < 0) {
- if (errno == EINTR)
- continue;
- else if (errno == EAGAIN)
+ if (errno == EINTR) {
continue;
- else if (errno == EWOULDBLOCK)
+ } else if (errno == EAGAIN) { /* same as EWOULDBLOCK */
+ if (false == retry) {
+ clock_gettime(CLOCK_MONOTONIC, &st);
+ retry = true;
+ } else {
+ int diff_msec = _sub_timespec_in_msec(&st);
+ if (PIMS_RECVWAIT_MSEC < diff_msec) {
+ ERR("error! (%d) connection will be closed by timeout!", errno);
+ ERR("send timestamp (%ld.%ld)sec and wait (%d)msec", st.tv_sec, st.tv_nsec, diff_msec);
+ free(*buf);
+ *buf = NULL;
+ return -1;
+ }
+ }
continue;
+ }
else if (errno == EPIPE) {
ERR("connection closed : read err %d, read_lenn %d, length %u", errno, read_len, length);
free(*buf);