version 1.15, 2011/01/10 20:59:42 |
version 1.16, 2013/04/20 19:02:57 |
|
|
#endif |
#endif |
#include <string.h> |
#include <string.h> |
#include <errno.h> |
#include <errno.h> |
|
#include <poll.h> |
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/ioctl.h> |
#include <sys/ioctl.h> |
#ifdef HAVE_SYS_WAIT_H |
#ifdef HAVE_SYS_WAIT_H |
|
|
if ((canbepipe && (ioctl(fd, FIONREAD, &t) == -1)) || (t == 0)) { |
if ((canbepipe && (ioctl(fd, FIONREAD, &t) == -1)) || (t == 0)) { |
#ifdef FD_ZERO |
#ifdef FD_ZERO |
for (cnt = 0;; cnt++) { |
for (cnt = 0;; cnt++) { |
fd_set check; |
struct pollfd pfd[1]; |
struct timeval tout = {0, 100 * 1000}; |
int rv; |
int selrv; |
|
|
|
FD_ZERO(&check); |
pfd[0].fd = fd; |
FD_SET(fd, &check); |
pfd[0].events = POLLIN; |
|
|
/* |
/* |
* Avoid soft deadlock: do not read if there |
* Avoid soft deadlock: do not read if there |
* is nothing to read from sockets and pipes. |
* is nothing to read from sockets and pipes. |
*/ |
*/ |
selrv = select(fd + 1, &check, NULL, NULL, &tout); |
rv = poll(pfd, 1, 100); |
if (selrv == -1) { |
if (rv == -1) { |
if (errno == EINTR || errno == EAGAIN) |
if (errno == EINTR || errno == EAGAIN) |
continue; |
continue; |
} else if (selrv == 0 && cnt >= 5) { |
} else if (rv == 0 && cnt >= 5) { |
return 0; |
return 0; |
} else |
} else |
break; |
break; |