summaryrefslogtreecommitdiff
path: root/ao-tools/libaltos/libaltos.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2010-09-03 12:43:45 -0700
committerKeith Packard <keithp@keithp.com>2010-09-03 12:43:45 -0700
commit59798c6fd11502a9c8b66090c23ba50eb250692e (patch)
treec8ea2547ca7c626bab2d401e2d96720ab06d61da /ao-tools/libaltos/libaltos.c
parent16d8d6a8853d09f683b13f9cda3c3174a0aab130 (diff)
altosui: Catch I/O errors on telemetry device, report to user
This catches the USB device being unplugged and makes sure the user sees an error dialog in this case. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'ao-tools/libaltos/libaltos.c')
-rw-r--r--ao-tools/libaltos/libaltos.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/ao-tools/libaltos/libaltos.c b/ao-tools/libaltos/libaltos.c
index 059d2ae9..465f0ac8 100644
--- a/ao-tools/libaltos/libaltos.c
+++ b/ao-tools/libaltos/libaltos.c
@@ -576,6 +576,11 @@ altos_free(struct altos_file *file)
PUBLIC int
altos_flush(struct altos_file *file)
{
+ if (file->out_used && 0) {
+ printf ("flush \"");
+ fwrite(file->out_data, 1, file->out_used, stdout);
+ printf ("\"\n");
+ }
while (file->out_used) {
int ret;
@@ -634,7 +639,7 @@ altos_fill(struct altos_file *file, int timeout)
return LIBALTOS_ERROR;
#ifdef USE_POLL
fd[0].fd = file->fd;
- fd[0].events = POLLIN;
+ fd[0].events = POLLIN|POLLERR|POLLHUP|POLLNVAL;
fd[1].fd = file->pipe[0];
fd[1].events = POLLIN;
ret = poll(fd, 2, timeout);
@@ -644,6 +649,9 @@ altos_fill(struct altos_file *file, int timeout)
}
if (ret == 0)
return LIBALTOS_TIMEOUT;
+
+ if (fd[0].revents & (POLLHUP|POLLERR|POLLNVAL))
+ return LIBALTOS_ERROR;
if (fd[0].revents & POLLIN)
#endif
{
@@ -660,6 +668,11 @@ altos_fill(struct altos_file *file, int timeout)
#endif
}
}
+ if (file->in_used && 0) {
+ printf ("fill \"");
+ fwrite(file->in_data, 1, file->in_used, stdout);
+ printf ("\"\n");
+ }
return 0;
}