Chromium Code Reviews| 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; |
| } |