char buff[CMSG_SPACE(sizeof(int) * MAX_NR_OF_DESCRIPTORS) + CMSG_SPACE(50)] = {0};
struct msghdr msg = {0};
struct cmsghdr *cmsg = NULL;
+ bool is_blocking;
int ret;
if (vec == NULL || vec_max_size < 1 || vec_size == NULL)
msg.msg_control = buff;
msg.msg_controllen = sizeof(buff);
+ if (fcntl(sock, F_GETFL, 0) & O_NONBLOCK)
+ is_blocking = false;
+ else
+ is_blocking = true;
+
+retry:
ret = recvmsg(sock, &msg, 0);
- if (ret < 0)
- return -errno;
+ if (ret == 0) {
+ _W("Socket was disconnected. fd(%d)", sock);
+ return -ECOMM;
+ } else if (ret < 0) {
+ if (errno == EINTR || errno == EAGAIN) {
+ if (is_blocking && errno == EAGAIN) {
+ _E("recvmsg timeout. fd(%d)", sock);
+ return -EAGAIN;
+ }
+
+ goto retry;
+ }
+
+ ret = -errno;
+ _E("recvmsg error. fd(%d), errno(%d)", sock, errno);
+ return ret;
+ }
+
*vec_size = msg.msg_iovlen;
/* get the ANCILLARY data */