ASMessage *CheckASMessageFine (int t_sec, int t_usec) { fd_set in_fdset; ASMessage *msg = NULL; struct timeval tv; int fd = get_module_in_fd (); if (fd < 0) return NULL; FD_ZERO (&in_fdset); FD_SET (fd, &in_fdset); tv.tv_sec = t_sec; tv.tv_usec = t_usec; #ifdef __hpux while (select (fd + 1, (int *)&in_fdset, 0, 0, (t_sec < 0) ? NULL : &tv) == -1) if (errno != EINTR) break; #else while (select (fd + 1, &in_fdset, 0, 0, (t_sec < 0) ? NULL : &tv) == -1) if (errno != EINTR) break; #endif if (FD_ISSET (fd, &in_fdset)) { msg = (ASMessage *) safecalloc (1, sizeof (ASMessage)); if (ReadASPacket (fd, msg->header, &(msg->body)) <= 0) { free (msg); msg = NULL; } } return msg; }
static void read_as_socket () { unsigned long header[3], *body; if (ReadASPacket (fd[1], header, &body) > 0) { process_message (header[1], header[2], body); free (body); } }
void module_wait_pipes_input (void (*as_msg_handler) (send_data_type type, send_data_type * body)) { fd_set in_fdset, out_fdset; int retval; struct timeval tv; struct timeval *t = NULL; int max_fd = 0; ASMessage msg; int as_fd = get_module_in_fd (); FD_ZERO (&in_fdset); FD_ZERO (&out_fdset); FD_SET (x_fd, &in_fdset); max_fd = x_fd; if (as_fd >= 0) { FD_SET (as_fd, &in_fdset); if (max_fd < as_fd) max_fd = as_fd; } if (timer_delay_till_next_alarm ((time_t *) & tv.tv_sec, (time_t *) & tv.tv_usec)) t = &tv; retval = PORTABLE_SELECT (min (max_fd + 1, fd_width), &in_fdset, &out_fdset, NULL, t); if (retval > 0) { /* check for incoming module connections */ if (as_fd >= 0) if (FD_ISSET (as_fd, &in_fdset)) if (ReadASPacket (as_fd, msg.header, &(msg.body)) > 0) { as_msg_handler (msg.header[1], msg.body); free (msg.body); } } /* handle timeout events */ timer_handle (); }