Index: base/sync_socket_posix.cc |
diff --git a/base/sync_socket_posix.cc b/base/sync_socket_posix.cc |
index 257916df3357a21962a4f6b9fe7561a09c286d50..df962fe525121321cd1251020e0b9265bdfc0ac7 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::Receive(void* buffer, size_t length, |
+ base::TimeDelta timeout) { |
+ // TODO(dalecurtis): Build fd_set during construction? |
tommi (sloooow) - chröme
2013/08/20 10:55:57
would this make a measurable difference?
DaleCurtis
2013/09/11 01:16:03
Probably not. Comment removed.
|
+ fd_set rfds; |
+ FD_ZERO(&rfds); |
+ FD_SET(handle_, &rfds); |
+ |
+ // TODO(dalecurtis): Fill out seconds. Can't use Time::ToTimeVal since it |
+ // expects time relative to 1970. |
+ struct timeval timeout_struct = { 0, timeout.InMicroseconds() }; |
miu
2013/08/17 02:39:13
Since you're not populating the "seconds" part, co
DaleCurtis
2013/09/11 01:16:03
Done.
|
+ int select_result = HANDLE_EINTR( |
+ select(handle_ + 1, &rfds, NULL, NULL, &timeout_struct)); |
+ if (select_result <= 0) |
+ return 0; |
+ |
+ DCHECK_LE(length, kMaxMessageLength); |
+ char* charbuffer = static_cast<char*>(buffer); |
+ if (file_util::ReadFromFD(handle_, charbuffer, length)) |
tommi (sloooow) - chröme
2013/08/20 10:55:57
don't you first have to check if handle_ is in rfd
DaleCurtis
2013/08/20 18:27:51
Not if we only have one descriptor since select()
tommi (sloooow) - chröme
2013/08/21 12:33:26
sgtm
|
+ return length; |
+ return 0; |
+} |
+ |
size_t SyncSocket::Peek() { |
int number_chars; |
if (-1 == ioctl(handle_, FIONREAD, &number_chars)) { |