Fixed data loss in writes to pty masters. Data was almost always lost

at the end of each write for writes of more than 1K.

Fixed handling of residual count for early returns in writes to pty masters.
It was only adjusted in 2 out of 6 cases.

Added prototypes.
This commit is contained in:
Bruce Evans 1995-10-25 18:23:58 +00:00
parent 12bc45a8df
commit e2f15ca546

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)tty_pty.c 8.2 (Berkeley) 9/23/93
* $Id: tty_pty.c,v 1.20 1995/09/08 11:08:38 bde Exp $
* $Id: tty_pty.c,v 1.21 1995/09/19 12:26:47 bde Exp $
*/
/*
@ -52,6 +52,10 @@
#include <sys/vnode.h>
#include <sys/signalvar.h>
void ptyattach __P((int n));
void ptsstart __P((struct tty *tp));
void ptcwakeup __P((struct tty *tp, int flag));
#if NPTY == 1
#undef NPTY
#define NPTY 32 /* crude XXX */
@ -486,7 +490,8 @@ ptcwrite(dev, uio, flag)
if (pti->pt_flags & PF_REMOTE) {
if (tp->t_canq.c_cc)
goto block;
while (uio->uio_resid > 0 && tp->t_canq.c_cc < TTYHOG - 1) {
while ((uio->uio_resid > 0 || cc > 0) &&
tp->t_canq.c_cc < TTYHOG - 1) {
if (cc == 0) {
cc = min(uio->uio_resid, BUFSIZ);
cc = min(cc, TTYHOG - 1 - tp->t_canq.c_cc);
@ -495,19 +500,23 @@ ptcwrite(dev, uio, flag)
if (error)
return (error);
/* check again for safety */
if ((tp->t_state&TS_ISOPEN) == 0)
if ((tp->t_state & TS_ISOPEN) == 0) {
/* adjust as usual */
uio->uio_resid += cc;
return (EIO);
}
}
if (cc)
(void) b_to_q((char *)cp, cc, &tp->t_canq);
cc = 0;
cc -= b_to_q((char *)cp, cc, &tp->t_canq);
}
/* adjust for data copied in but not written */
uio->uio_resid += cc;
(void) putc(0, &tp->t_canq);
ttwakeup(tp);
wakeup(TSA_PTS_READ(tp));
return (0);
}
while (uio->uio_resid > 0) {
while (uio->uio_resid > 0 || cc > 0) {
if (cc == 0) {
cc = min(uio->uio_resid, BUFSIZ);
cp = locbuf;
@ -515,8 +524,11 @@ ptcwrite(dev, uio, flag)
if (error)
return (error);
/* check again for safety */
if ((tp->t_state&TS_ISOPEN) == 0)
if ((tp->t_state & TS_ISOPEN) == 0) {
/* adjust for data copied in but not written */
uio->uio_resid += cc;
return (EIO);
}
}
while (cc > 0) {
if ((tp->t_rawq.c_cc + tp->t_canq.c_cc) >= TTYHOG - 2 &&
@ -536,8 +548,11 @@ ptcwrite(dev, uio, flag)
* Come here to wait for slave to open, for space
* in outq, or space in rawq.
*/
if ((tp->t_state & TS_CONNECTED) == 0)
if ((tp->t_state & TS_CONNECTED) == 0) {
/* adjust for data copied in but not written */
uio->uio_resid += cc;
return (EIO);
}
if (flag & IO_NDELAY) {
/* adjust for data copied in but not written */
uio->uio_resid += cc;