Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Unified Diff: tools/android/forwarder2/socket.cc

Issue 2402793002: [Android] Add timeout to unmap reply handling. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/android/forwarder2/socket.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/android/forwarder2/socket.cc
diff --git a/tools/android/forwarder2/socket.cc b/tools/android/forwarder2/socket.cc
index 669764f0e4297ae72f5da37c521178e9475495cb..65dcbd0b579b9e750f5738db91d4dce0e6979012 100644
--- a/tools/android/forwarder2/socket.cc
+++ b/tools/android/forwarder2/socket.cc
@@ -294,10 +294,17 @@ int Socket::GetPort() {
}
int Socket::ReadNumBytes(void* buffer, size_t num_bytes) {
+ return ReadNumBytesWithTimeout(buffer, num_bytes, kNoTimeout);
+}
+
+int Socket::ReadNumBytesWithTimeout(void* buffer,
+ size_t num_bytes,
+ int timeout_secs) {
size_t bytes_read = 0;
int ret = 1;
while (bytes_read < num_bytes && ret > 0) {
- ret = Read(static_cast<char*>(buffer) + bytes_read, num_bytes - bytes_read);
+ ret = ReadWithTimeout(static_cast<char*>(buffer) + bytes_read,
+ num_bytes - bytes_read, timeout_secs);
if (ret >= 0)
bytes_read += ret;
}
@@ -312,7 +319,13 @@ void Socket::SetSocketError() {
}
int Socket::Read(void* buffer, size_t buffer_size) {
- if (!WaitForEvent(READ, kNoTimeout)) {
+ return ReadWithTimeout(buffer, buffer_size, kNoTimeout);
+}
+
+int Socket::ReadWithTimeout(void* buffer,
+ size_t buffer_size,
+ int timeout_secs) {
+ if (!WaitForEvent(READ, timeout_secs)) {
SetSocketError();
return 0;
}
@@ -419,8 +432,8 @@ bool Socket::WaitForEvent(EventType type, int timeout_secs) {
for (size_t i = 0; i < events_.size(); ++i)
if (events_[i].fd > max_fd)
max_fd = events_[i].fd;
- if (HANDLE_EINTR(
- select(max_fd + 1, &read_fds, &write_fds, NULL, tv_ptr)) <= 0) {
+ if (HANDLE_EINTR(select(max_fd + 1, &read_fds, &write_fds, NULL, tv_ptr)) <
Ted C 2016/10/08 00:16:32 i think the line wrapping before was easier to gro
jbudorick 2016/10/08 00:30:58 as did I, but git cl format disagreed.
+ 0) {
PLOG(ERROR) << "select";
return false;
}
« no previous file with comments | « tools/android/forwarder2/socket.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698