pty: don't writev() if buffers are empty

If there's nothing to write, we shouldn't call into writev().

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
pty: flush writes even if read stalled

We first dispatch read()s to allow callbacks to fill write-buffers. So the
following write()s will flush this data. This patch makes sure the
following write() is done even if input data is still available.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
test_pty: correctly dispatch I/O

Fix I/O dispatching and introduce counter to avoid race-conditions. Also
explain why we get the message twice (via TTY ECHO mode).

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>