Cygwin: pty, termios: Unify thoughts of read ahead beffer handling.
- Return value of eat_readahead() is redefined. The return values of fhandler_termios::eat_readahead() and fhandler_pty_slave:: eat_readahead() were little bit different. This patch unifies them to number of bytes eaten by eat_readahead(). - Considerration for raixget() is added to fhandler_pty_master:: accept_input() code. - Transfering contents of read ahead buffer in fhandler_pty_master::transfer_input_to_pcon() is removed since it is not necessary. - fhandler_pty_slave::eat_readahead() ckecks EOL only when ICANON is set. - Guard for _POSIX_VDISABLE is added in checking EOL.
This commit is contained in:
parent
8121b606e8
commit
c11b0343c0
@ -268,25 +268,25 @@ fhandler_termios::eat_readahead (int n)
|
|||||||
{
|
{
|
||||||
int oralen = ralen ();
|
int oralen = ralen ();
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
n = ralen ();
|
n = ralen () - raixget ();
|
||||||
if (n > 0 && ralen () > 0)
|
if (n > 0 && ralen () > raixget ())
|
||||||
{
|
{
|
||||||
if ((int) (ralen () -= n) < 0)
|
if ((int) (ralen () -= n) < (int) raixget ())
|
||||||
ralen () = 0;
|
ralen () = raixget ();
|
||||||
/* If IUTF8 is set, the terminal is in UTF-8 mode. If so, we erase
|
/* If IUTF8 is set, the terminal is in UTF-8 mode. If so, we erase
|
||||||
a complete UTF-8 multibyte sequence on VERASE/VWERASE. Otherwise,
|
a complete UTF-8 multibyte sequence on VERASE/VWERASE. Otherwise,
|
||||||
if we only erase a single byte, invalid unicode chars are left in
|
if we only erase a single byte, invalid unicode chars are left in
|
||||||
the input. */
|
the input. */
|
||||||
if (tc ()->ti.c_iflag & IUTF8)
|
if (tc ()->ti.c_iflag & IUTF8)
|
||||||
while (ralen () > 0 &&
|
while (ralen () > raixget () &&
|
||||||
((unsigned char) rabuf ()[ralen ()] & 0xc0) == 0x80)
|
((unsigned char) rabuf ()[ralen ()] & 0xc0) == 0x80)
|
||||||
--ralen ();
|
--ralen ();
|
||||||
|
}
|
||||||
|
oralen = oralen - ralen ();
|
||||||
if (raixget () >= ralen ())
|
if (raixget () >= ralen ())
|
||||||
raixget () = raixput () = ralen () = 0;
|
raixget () = raixput () = ralen () = 0;
|
||||||
else if (raixput () > ralen ())
|
else if (raixput () > ralen ())
|
||||||
raixput () = ralen ();
|
raixput () = ralen ();
|
||||||
}
|
|
||||||
|
|
||||||
return oralen;
|
return oralen;
|
||||||
}
|
}
|
||||||
|
@ -548,6 +548,7 @@ fhandler_pty_master::accept_input ()
|
|||||||
|
|
||||||
WaitForSingleObject (input_mutex, INFINITE);
|
WaitForSingleObject (input_mutex, INFINITE);
|
||||||
|
|
||||||
|
char *p = rabuf () + raixget ();
|
||||||
bytes_left = eat_readahead (-1);
|
bytes_left = eat_readahead (-1);
|
||||||
|
|
||||||
if (to_be_read_from_pcon ())
|
if (to_be_read_from_pcon ())
|
||||||
@ -559,7 +560,6 @@ fhandler_pty_master::accept_input ()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char *p = rabuf ();
|
|
||||||
DWORD rc;
|
DWORD rc;
|
||||||
DWORD written = 0;
|
DWORD written = 0;
|
||||||
|
|
||||||
@ -1171,10 +1171,10 @@ fhandler_pty_slave::update_pcon_input_state (bool need_lock)
|
|||||||
'\n',
|
'\n',
|
||||||
'\r'
|
'\r'
|
||||||
};
|
};
|
||||||
if (is_line_input () && memchr (eols, c, sizeof (eols)))
|
if (is_line_input () && c && memchr (eols, c, sizeof (eols)))
|
||||||
saw_accept = true;
|
saw_accept = true;
|
||||||
if ((get_ttyp ()->ti.c_lflag & ISIG) &&
|
if ((get_ttyp ()->ti.c_lflag & ISIG)
|
||||||
memchr (sigs, c, sizeof (sigs)))
|
&& c && memchr (sigs, c, sizeof (sigs)))
|
||||||
saw_accept = true;
|
saw_accept = true;
|
||||||
}
|
}
|
||||||
get_ttyp ()->pcon_in_empty = pipe_empty && !(ralen () > raixget ());
|
get_ttyp ()->pcon_in_empty = pipe_empty && !(ralen () > raixget ());
|
||||||
@ -1189,7 +1189,7 @@ fhandler_pty_slave::update_pcon_input_state (bool need_lock)
|
|||||||
int
|
int
|
||||||
fhandler_pty_slave::eat_readahead (int n)
|
fhandler_pty_slave::eat_readahead (int n)
|
||||||
{
|
{
|
||||||
int oralen = ralen () - raixget ();
|
int oralen = ralen ();
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
n = ralen () - raixget ();
|
n = ralen () - raixget ();
|
||||||
if (n > 0 && ralen () > raixget ())
|
if (n > 0 && ralen () > raixget ())
|
||||||
@ -1202,7 +1202,8 @@ fhandler_pty_slave::eat_readahead (int n)
|
|||||||
};
|
};
|
||||||
while (n > 0 && ralen () > raixget ())
|
while (n > 0 && ralen () > raixget ())
|
||||||
{
|
{
|
||||||
if (memchr (eols, rabuf ()[ralen ()-1], sizeof (eols)))
|
if (is_line_input () && rabuf ()[ralen ()-1]
|
||||||
|
&& memchr (eols, rabuf ()[ralen ()-1], sizeof (eols)))
|
||||||
break;
|
break;
|
||||||
-- n;
|
-- n;
|
||||||
-- ralen ();
|
-- ralen ();
|
||||||
@ -1213,15 +1214,15 @@ fhandler_pty_slave::eat_readahead (int n)
|
|||||||
if we only erase a single byte, invalid unicode chars are left in
|
if we only erase a single byte, invalid unicode chars are left in
|
||||||
the input. */
|
the input. */
|
||||||
if (get_ttyp ()->ti.c_iflag & IUTF8)
|
if (get_ttyp ()->ti.c_iflag & IUTF8)
|
||||||
while (ralen () > 0 &&
|
while (ralen () > raixget () &&
|
||||||
((unsigned char) rabuf ()[ralen ()] & 0xc0) == 0x80)
|
((unsigned char) rabuf ()[ralen ()] & 0xc0) == 0x80)
|
||||||
--ralen ();
|
--ralen ();
|
||||||
|
}
|
||||||
|
oralen = oralen - ralen ();
|
||||||
if (raixget () >= ralen ())
|
if (raixget () >= ralen ())
|
||||||
raixget () = raixput () = ralen () = 0;
|
raixget () = raixput () = ralen () = 0;
|
||||||
else if (raixput () > ralen ())
|
else if (raixput () > ralen ())
|
||||||
raixput () = ralen ();
|
raixput () = ralen ();
|
||||||
}
|
|
||||||
|
|
||||||
return oralen;
|
return oralen;
|
||||||
}
|
}
|
||||||
@ -1245,7 +1246,7 @@ fhandler_pty_slave::get_readahead_into_buffer (char *buf, size_t buflen)
|
|||||||
};
|
};
|
||||||
buf[copied_chars++] = (unsigned char)(ch & 0xff);
|
buf[copied_chars++] = (unsigned char)(ch & 0xff);
|
||||||
buflen--;
|
buflen--;
|
||||||
if (is_line_input () && memchr (eols, ch & 0xff, sizeof (eols)))
|
if (is_line_input () && ch && memchr (eols, ch & 0xff, sizeof (eols)))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1264,7 +1265,7 @@ fhandler_pty_slave::get_readahead_valid (void)
|
|||||||
'\n'
|
'\n'
|
||||||
};
|
};
|
||||||
for (size_t i=raixget (); i<ralen (); i++)
|
for (size_t i=raixget (); i<ralen (); i++)
|
||||||
if (memchr (eols, rabuf ()[i], sizeof (eols)))
|
if (rabuf ()[i] && memchr (eols, rabuf ()[i], sizeof (eols)))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -2554,7 +2555,7 @@ fhandler_pty_master::write (const void *ptr, size_t len)
|
|||||||
};
|
};
|
||||||
if (tc ()->ti.c_lflag & ISIG)
|
if (tc ()->ti.c_lflag & ISIG)
|
||||||
for (size_t i=0; i<sizeof (sigs); i++)
|
for (size_t i=0; i<sizeof (sigs); i++)
|
||||||
if (memchr (buf, sigs[i], nlen))
|
if (sigs[i] && memchr (buf, sigs[i], nlen))
|
||||||
{
|
{
|
||||||
eat_readahead (-1);
|
eat_readahead (-1);
|
||||||
SetEvent (input_available_event);
|
SetEvent (input_available_event);
|
||||||
@ -3224,12 +3225,6 @@ fhandler_pty_master::transfer_input_to_pcon (void)
|
|||||||
if (WriteFile (to_slave, buf, n, &n, 0))
|
if (WriteFile (to_slave, buf, n, &n, 0))
|
||||||
transfered += n;
|
transfered += n;
|
||||||
}
|
}
|
||||||
DWORD bytes_left = eat_readahead (-1);
|
|
||||||
if (bytes_left)
|
|
||||||
{
|
|
||||||
if (WriteFile (to_slave, rabuf (), bytes_left, &n, NULL))
|
|
||||||
transfered += n;
|
|
||||||
}
|
|
||||||
if (transfered)
|
if (transfered)
|
||||||
get_ttyp ()->pcon_in_empty = false;
|
get_ttyp ()->pcon_in_empty = false;
|
||||||
ReleaseMutex (input_mutex);
|
ReleaseMutex (input_mutex);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user