/* * It is a frontend to tty_select(), that also checks our program buffer */ int tty_xselect(bool *rd, bool *wr, int timeout) { if( rd && rx_pos > 0 ) { (void)tty_select(NULL, wr, 0); *rd = TRUE; return TTY_SUCCESS; } return tty_select(rd, wr, timeout); }
static status_t master_select(void *_cookie, uint8 event, uint32 ref, selectsync *sync) { master_cookie *cookie = (master_cookie *)_cookie; return tty_select(cookie, event, ref, sync); }
/* * On success return number of bytes received */ int tty_read_timeout(unsigned char *buf, size_t size, int timeout) { int rc; bool rd = FALSE; tty_status = TTY_SUCCESS; DEB((D_TTYIO, "tty_read_timeout: want read %d byte(s), timeout = %d", size, timeout)); if( timeout > 0 ) { if( (rc = tty_select(&rd, NULL, timeout)) < 0 ) return rc; if( rd ) { if( (rc = tty_read(buf, size)) == 0 ) return TTY_ERROR; return rc; } return TTY_TIMEOUT; } return tty_read(buf, size); }
/* * Return non-zero value if some data available for reading * in input queue OR in our RX buffer */ int tty_charwait(int timeout) { bool rd = FALSE; if( rx_pos > 0 ) return 1; else if( tty_select(&rd, NULL, timeout) == 0 && rd == TRUE ) return 1; else return 0; }