Add an implementation of base::SyncSocket::Peek for posix platforms. Also
update the unit test to test the result.
TEST=ipc_tests/sync_socket_unittest.cc
Review URL: http://codereview.chromium.org/468023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33944 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/base/sync_socket_posix.cc b/base/sync_socket_posix.cc
index 5390c7d..194c0bc 100644
--- a/base/sync_socket_posix.cc
+++ b/base/sync_socket_posix.cc
@@ -8,6 +8,7 @@
#include <limits.h>
#include <stdio.h>
#include <sys/types.h>
+#include <sys/ioctl.h>
#include <sys/socket.h>
#include "base/atomicops.h"
@@ -98,10 +99,13 @@
}
}
-// TODO(port). Some kind of select?
size_t SyncSocket::Peek() {
- NOTIMPLEMENTED();
- return 0;
+ int number_chars;
+ if (-1 == ioctl(handle_, FIONREAD, &number_chars)) {
+ // If there is an error in ioctl, signal that the channel would block.
+ return 0;
+ }
+ return (size_t) number_chars;
}
} // namespace base