summaryrefslogtreecommitdiffstats
path: root/device/hid/hid_connection_linux.cc
diff options
context:
space:
mode:
authorreillyg <reillyg@chromium.org>2014-12-18 15:39:44 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-18 23:40:45 +0000
commit4eeb93839c0bf4ac206467be0e3dc7b9d0ffbb40 (patch)
treecb308dbc7bb2581f4aad01b275515e3849cdfeeb /device/hid/hid_connection_linux.cc
parent3f178cfa116c79caec62df13b123fb179507e085 (diff)
downloadchromium_src-4eeb93839c0bf4ac206467be0e3dc7b9d0ffbb40.zip
chromium_src-4eeb93839c0bf4ac206467be0e3dc7b9d0ffbb40.tar.gz
chromium_src-4eeb93839c0bf4ac206467be0e3dc7b9d0ffbb40.tar.bz2
Catch HID read errors on Linux and stop listening.
When a HID connection is broken read(2) will start returning errors. If the app that opened the device does not notice that it is disconnected then the file thread will spin on trying (and failing) to read more data from the device. This change stops the FileDescriptorWatcher when a read error is encountered. BUG= Review URL: https://codereview.chromium.org/809253002 Cr-Commit-Position: refs/heads/master@{#309103}
Diffstat (limited to 'device/hid/hid_connection_linux.cc')
-rw-r--r--device/hid/hid_connection_linux.cc11
1 files changed, 8 insertions, 3 deletions
diff --git a/device/hid/hid_connection_linux.cc b/device/hid/hid_connection_linux.cc
index 5347a89..47ae825 100644
--- a/device/hid/hid_connection_linux.cc
+++ b/device/hid/hid_connection_linux.cc
@@ -76,10 +76,15 @@ class HidConnectionLinux::Helper : public base::MessagePumpLibevent::Watcher {
ssize_t bytes_read = HANDLE_EINTR(read(platform_file_, data, length));
if (bytes_read < 0) {
- if (errno == EAGAIN) {
- return;
+ if (errno != EAGAIN) {
+ VPLOG(1) << "Read failed";
+ // This assumes that the error is unrecoverable and disables reading
+ // from the device until it has been re-opened.
+ // TODO(reillyg): Investigate starting and stopping the file descriptor
+ // watcher in response to pending read requests so that per-request
+ // errors can be returned to the client.
+ file_watcher_.StopWatchingFileDescriptor();
}
- VPLOG(1) << "Read failed";
return;
}
if (!has_report_id_) {