int process(struct ctx_t *ctx) { uint8_t *pkt; struct transport_msg_t msg; while ( (pkt = readpkt(&ctx->in, &msg)) != NULL ) { ctx->dump_f(&msg, ctx->outfh, ctx->user_ctx); } return ctx->in.last_errno; }
/*select may return before timer expires, re-run select */ int readWithTimer(int fd, char *pkt, int ms) { int s; fd_set fds; struct timeval tv; double entry_time=now(); int remain_time=ms; int len; do { tv.tv_sec = remain_time / 1000; tv.tv_usec = (remain_time - tv.tv_sec * 1000) * 1000; FD_ZERO(&fds); FD_SET(fd, &fds); s = select(fd + 1, &fds, 0, 0, &tv); remain_time = ms - (int)((now() - entry_time)*1000); if (s == -1) { perror("Internal Error!"); fflush(stderr); return(RMTP_TIMED_OUT); } if (s == 0) continue; if (FD_ISSET(fd, &fds)) { len = readpkt(fd, pkt, RMTP_MAXPKT + sizeof(struct rmtphdr)); if (len <= 0) continue; return len; } } while (remain_time > 100); return (RMTP_TIMED_OUT); }