From f1499d1d4518674c6c3c5c859a7028709bdd741d Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Sat, 24 Sep 2016 16:11:50 -0700 Subject: Use evented I/O for the pty This was largely an experiment to see whether writing and reading from a separate thread was causing terminal state corruption as described in https://github.com/jwilm/alacritty/issues/9. Although this doesn't seem to fix that particular issue. Keeping this because it generally seems more correct than reading/writing from separate locations. --- src/tty.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/tty.rs') diff --git a/src/tty.rs b/src/tty.rs index accf0226..988db37e 100644 --- a/src/tty.rs +++ b/src/tty.rs @@ -274,6 +274,12 @@ pub fn new(rows: u8, cols: u8) -> Tty { libc::close(slave); } + unsafe { + // Maybe this should be done outside of this function so nonblocking + // isn't forced upon consumers. Although maybe it should be? + set_nonblocking(master); + } + Tty { fd: master } } } @@ -320,6 +326,13 @@ impl Tty { } } +unsafe fn set_nonblocking(fd: c_int) { + use libc::{fcntl, F_SETFL, F_GETFL, O_NONBLOCK}; + + let res = fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK); + assert_eq!(res, 0); +} + #[test] fn test_get_pw_entry() { let mut buf: [i8; 1024] = [0; 1024]; -- cgit