#include "pims-ipc-data-internal.h"
#include "pims-ipc.h"
+#define PIMS_POLL_WAIT_MSEC 4500
+
#define GET_CALL_SEQUNECE_NO(handle, sequence_no) do {\
sequence_no = ++((handle)->call_sequence_no);\
} while (0)
/* end deprecated */
static pthread_mutex_t __disconnect_cb_mutex = PTHREAD_MUTEX_INITIALIZER;
+static int _sub_timespec_in_msec(struct timespec *st)
+{
+ struct timespec et = {0};
+ clock_gettime(CLOCK_MONOTONIC, &et);
+
+ /* 3 digits for sec, 3 digits for msec */
+ int s_msec = ((st->tv_sec % 1000) * 1000) + (st->tv_nsec / 1000000);
+ int e_msec = ((et.tv_sec % 1000) * 1000) + (et.tv_nsec / 1000000);
+
+ if (e_msec < s_msec)
+ e_msec += (1000 * 1000);
+
+ return e_msec - s_msec;
+}
+
static void __sub_data_free(gpointer user_data)
{
pims_ipc_subscribe_data_s *data = (pims_ipc_subscribe_data_s*)user_data;
pollfds[0].events = POLLIN | POLLERR | POLLHUP;
pollfds[0].revents = 0;
+ bool retry = false;
+ struct timespec st = {0};
+
while (1) {
while (1) {
- ret = poll(pollfds, 1, 4500);
- if (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK))
+ clock_gettime(CLOCK_MONOTONIC, &st);
+ ret = poll(pollfds, 1, PIMS_POLL_WAIT_MSEC);
+ if (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)) {
continue;
+ }
break;
}
- if (ret == 0){
- ERR("timedout errno[%d], revents[%d]", errno, pollfds[0].revents);
- return -1;
+ if (ret == 0) {
+ WARN("timeout errno[%d], revents[%d]", errno, pollfds[0].revents);
+ // it seems that system suspend affects poll()'s timeout
+ // so need to check timeout is occurred normally by using monotonic timeout logic
+ int diff_msec = _sub_timespec_in_msec(&st);
+ if (PIMS_POLL_WAIT_MSEC <= diff_msec) {
+ ERR("real timeout is occurred!");
+ ERR("timestamp (%ld.%ld)sec and wait (%d)msec", st.tv_sec, st.tv_nsec, diff_msec);
+ return -1;
+ }
+ continue;
}
+
if (ret > 0) {
if (pollfds[0].revents & (POLLERR|POLLHUP)) {
ERR("Server disconnected ret[%d]", ret);