* Allocate buffer space if necessary, and set low watermarks, based on speed. * Note that the ttyxxxq_setsize() functions may drop and then reacquire the tty * lock during memory allocation. They will return ENXIO if the tty disappears * while unlocked. */
| 122 | * while unlocked. |
| 123 | */ |
| 124 | static int |
| 125 | tty_watermarks(struct tty *tp) |
| 126 | { |
| 127 | size_t bs = 0; |
| 128 | int error; |
| 129 | |
| 130 | /* Provide an input buffer for 2 seconds of data. */ |
| 131 | if (tp->t_termios.c_cflag & CREAD) |
| 132 | bs = MIN(tp->t_termios.c_ispeed / 5, TTYBUF_MAX); |
| 133 | error = ttyinq_setsize(&tp->t_inq, tp, bs); |
| 134 | if (error != 0) |
| 135 | return (error); |
| 136 | |
| 137 | /* Set low watermark at 10% (when 90% is available). */ |
| 138 | tp->t_inlow = (ttyinq_getallocatedsize(&tp->t_inq) * 9) / 10; |
| 139 | |
| 140 | /* Provide an output buffer for 2 seconds of data. */ |
| 141 | bs = MIN(tp->t_termios.c_ospeed / 5, TTYBUF_MAX); |
| 142 | error = ttyoutq_setsize(&tp->t_outq, tp, bs); |
| 143 | if (error != 0) |
| 144 | return (error); |
| 145 | |
| 146 | /* Set low watermark at 10% (when 90% is available). */ |
| 147 | tp->t_outlow = (ttyoutq_getallocatedsize(&tp->t_outq) * 9) / 10; |
| 148 | |
| 149 | return (0); |
| 150 | } |
| 151 | |
| 152 | static int |
| 153 | tty_drain(struct tty *tp, int leaving) |
no test coverage detected