summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2017-04-03 21:27:03 -0700
committerJoe Wilm <jwilm@users.noreply.github.com>2017-04-03 21:34:21 -0700
commit9acd612b23ebd43511113a5c704ebbf5aca3cafc (patch)
treeb6beb36d28d3e80cf7ae81053664425da2976892 /src
parent52c979bc0843dc2b820db97aaff8b58b6ad9d675 (diff)
Better error handling in event loop
Also checks hup first since if the terminal is either not readable or writable there's nothing for Alacritty to do. Closes #480.
Diffstat (limited to 'src')
-rw-r--r--src/event_loop.rs34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/event_loop.rs b/src/event_loop.rs
index 483490f0..2cee471c 100644
--- a/src/event_loop.rs
+++ b/src/event_loop.rs
@@ -206,7 +206,7 @@ impl<Io> EventLoop<Io>
state: &mut State,
buf: &mut [u8],
mut writer: Option<&mut W>
- )
+ ) -> io::Result<()>
where W: Write
{
loop {
@@ -249,15 +249,17 @@ impl<Io> EventLoop<Io>
match err.kind() {
ErrorKind::Interrupted |
ErrorKind::WouldBlock => break,
- _ => panic!("unexpected read err: {:?}", err),
+ _ => return Err(err),
}
}
}
}
+
+ Ok(())
}
#[inline]
- fn pty_write(&mut self, state: &mut State) {
+ fn pty_write(&mut self, state: &mut State) -> io::Result<()> {
state.ensure_next();
'write_many: while let Some(mut current) = state.take_current() {
@@ -279,14 +281,15 @@ impl<Io> EventLoop<Io>
match err.kind() {
ErrorKind::Interrupted |
ErrorKind::WouldBlock => break 'write_many,
- // TODO
- _ => panic!("unexpected err: {:?}", err),
+ _ => return Err(err),
}
}
}
}
}
+
+ Ok(())
}
pub fn spawn(
@@ -329,19 +332,28 @@ impl<Io> EventLoop<Io>
PTY => {
let kind = event.kind();
+ if kind.is_hup() {
+ break 'event_loop;
+ }
+
if kind.is_readable() {
- self.pty_read(&mut state, &mut buf, pipe.as_mut());
+ if let Err(err) = self.pty_read(&mut state, &mut buf, pipe.as_mut()) {
+ error!("Event loop exitting due to error: {} [{}:{}]",
+ err, file!(), line!());
+ break 'event_loop;
+ }
+
if ::tty::process_should_exit() {
break 'event_loop;
}
}
if kind.is_writable() {
- self.pty_write(&mut state);
- }
-
- if kind.is_hup() {
- break 'event_loop;
+ if let Err(err) = self.pty_write(&mut state) {
+ error!("Event loop exitting due to error: {} [{}:{}]",
+ err, file!(), line!());
+ break 'event_loop;
+ }
}
// Figure out pty interest