return -ERRNO_TO_PARA_ERROR(err);
}
+static int xpoll(struct pollfd *fds, nfds_t nfds, int timeout)
+{
+ int ret;
+
+ do
+ ret = poll(fds, nfds, timeout);
+ while (ret < 0 && errno == EINTR);
+ return ret < 0? -ERRNO_TO_PARA_ERROR(errno) : ret;
+}
+
+/**
+ * Check a file descriptor for readability.
+ *
+ * \param fd The file descriptor.
+ *
+ * \return positive if fd is ready for reading, zero if it isn't, negative if
+ * an error occurred.
+ *
+ * \sa \ref write_ok().
+ */
+int read_ok(int fd)
+{
+ struct pollfd pfd = {.fd = fd, .events = POLLIN};
+ int ret = xpoll(&pfd, 1, 0);
+ return ret < 0? ret : pfd.revents & POLLIN;
+}
+
/**
* Check a file descriptor for writability.
*
*
* \return positive if fd is ready for writing, zero if it isn't, negative if
* an error occurred.
+ *
+ * \sa \ref read_ok().
*/
int write_ok(int fd)
{
- int ret;
struct pollfd pfd = {.fd = fd, .events = POLLOUT};
-
- do
- ret = poll(&pfd, 1, 0);
- while (ret < 0 && errno == EINTR);
- if (ret < 0)
- return -ERRNO_TO_PARA_ERROR(errno);
- return pfd.revents & POLLOUT;
+ int ret = xpoll(&pfd, 1, 0);
+ return ret < 0? ret : pfd.revents & POLLOUT;
}
/**
int mmap_full_file(const char *filename, int open_mode, void **map,
size_t *size, int *fd_ptr);
int para_munmap(void *start, size_t length);
+int read_ok(int fd);
int write_ok(int fd);
void valid_fd_012(void);
int readv_nonblock(int fd, struct iovec *iov, int iovcnt, fd_set *rfds,
rl_point = point;
}
-static bool input_available(void)
-{
- fd_set rfds;
- int ret;
-
- FD_ZERO(&rfds);
- FD_SET(i9ep->ici->fds[0], &rfds);
- ret = para_select(1, &rfds, NULL, 0);
- return ret > 0;
-}
-
static void i9e_line_handler(char *line)
{
int ret;
ret = 0;
if (i9ep->caught_sigint)
goto rm_btrn;
- while (input_available()) {
+ while (read_ok(i9ep->ici->fds[0]) > 0) {
if (i9ep->stdout_btrn) {
while (i9ep->key_sequence_length < sizeof(i9ep->key_sequence) - 1) {
buf = i9ep->key_sequence + i9ep->key_sequence_length;
i9ep->key_sequence_length++;
rl_stuff_char((int)(unsigned char)*buf);
rl_callback_read_char();
- if (!input_available())
+ if (read_ok(i9ep->ici->fds[0]) <= 0)
break;
}
i9ep->key_sequence_length = 0;