Chromium Code Reviews| Index: base/sync_socket_posix.cc |
| diff --git a/base/sync_socket_posix.cc b/base/sync_socket_posix.cc |
| index 257916df3357a21962a4f6b9fe7561a09c286d50..0efa9f22a814c805d600a7081fea950baae94981 100644 |
| --- a/base/sync_socket_posix.cc |
| +++ b/base/sync_socket_posix.cc |
| @@ -108,6 +108,28 @@ size_t SyncSocket::Receive(void* buffer, size_t length) { |
| return 0; |
| } |
| +size_t SyncSocket::ReceiveWithTimeout(void* buffer, |
| + size_t length, |
| + TimeDelta timeout) { |
| + fd_set rfds; |
| + FD_ZERO(&rfds); |
| + FD_SET(handle_, &rfds); |
| + |
| + DCHECK(timeout.InMicroseconds() < Time::kMicrosecondsPerSecond); |
|
awong
2013/09/17 18:54:12
nit: DCHECK_LT?
DaleCurtis
2013/09/17 19:00:25
Doesn't work for some reason, ends up with a link
awong
2013/09/17 19:57:11
Oh right. It's cause there isn't a definition for
|
| + struct timeval timeout_struct = { 0, timeout.InMicroseconds() }; |
| + |
| + int select_result = HANDLE_EINTR( |
| + select(handle_ + 1, &rfds, NULL, NULL, &timeout_struct)); |
| + |
| + if (select_result > 0) { |
| + DCHECK(FD_ISSET(handle_, &rfds)); |
| + DCHECK_GE(Peek(), length); |
|
awong
2013/09/17 18:54:12
Why do we think Peek() can't be less than length?
DaleCurtis
2013/09/17 19:00:25
Correct, I'll remove the condition. For its inten
awong
2013/09/17 19:57:11
Do you want to read the amount from Peek() or the
DaleCurtis
2013/09/17 20:13:44
To be perfect this should be a while loop which ru
|
| + return Receive(buffer, length); |
| + } |
| + |
| + return 0; |
| +} |
| + |
| size_t SyncSocket::Peek() { |
| int number_chars; |
| if (-1 == ioctl(handle_, FIONREAD, &number_chars)) { |