static int do_connected(void) { while (!exitasap) { if (read_lines()) break; } /* Keep capturing lines as long as there are lines ready to read. */ while (!exitasap) { if (seq_next - seq_send >= startlines) return STATE_SENDING; switch (iopoll(io, 1, readwait)) { case -1: return STATE_EXITING; case 1: if (stdin_error) return exitoneof ? STATE_EXITING : STATE_SENDING; if (read_lines() > 0 || stdin_eof) return STATE_SENDING; continue; case 0: return STATE_SENDING; } } return STATE_EXITING; }
static int poll_both(void) { struct timeval timestamp; int ready; /* Sanity check to make sure no data is lost */ if (inbuf.io.buflen > inbuf.io.bufstart) { stdin_ready = IOPOLL_READ; sock_ready = 0; return 1; } /* Calculate remaining timeout */ gettimeofday(×tamp, 0); if (poll_timestamp.tv_sec != 0) { poll_timeout -= (timestamp.tv_sec - poll_timestamp.tv_sec) * 1000 + (timestamp.tv_usec - poll_timestamp.tv_usec) / 1000; if (poll_timeout < 0) poll_timeout = 0; } poll_timestamp = timestamp; io[0].fd = stdin_eof ? -1 : 0; io[0].events = stdin_eof ? 0 : IOPOLL_READ; io[1].fd = sock; io[1].events = IOPOLL_READ; switch (ready = iopoll(io, 2, poll_timeout)) { case -1: if (errno == EAGAIN || errno == EINTR) exitasap = 1; else die1sys(1, "Poll failed!"); return 0; case 0: poll_timeout = 0; return 0; default: if (stdin_error) { stdin_eof = 1; if (exitoneof || seq_next == seq_send) exitasap = 1; io[0].revents = 0; } return ready; } }
int lpr_write(uint8_t minor, uint8_t rawflag, uint8_t flag) { char *p = udata.u_base; minor; rawflag; flag; // shut up compiler while(udata.u_done < udata.u_count) { /* Note; on real hardware it might well be necessary to busy wait a bit just to get acceptable performance */ while (lpstat != 0xFF) { if (iopoll()) return udata.u_done; } /* FIXME: tidy up ugetc and sysio checks globally */ lpdata = ugetc(p++); udata.u_done++; } return udata.u_done; }
int lpr_write(uint_fast8_t minor, uint_fast8_t rawflag, uint_fast8_t flag) { uint8_t *p = udata.u_base; uint8_t *pe = p + udata.u_count; int n; irqflags_t irq; uint8_t buf[2]; buf[0]=0x50; if (minor == 0) { while (p < pe) { if ((n = iopoll(pe - p)) != 0) return n; buf[1] = ugetc(p++); dw_transaction(buf, 2, NULL, 0, 0); } } return udata.u_count; }