From 1e1f1a7eb400cfd9094262315fc03d6a4e13fa1b Mon Sep 17 00:00:00 2001 From: "sehr@google.com" Date: Sun, 6 Dec 2009 19:45:08 +0000 Subject: 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 --- base/sync_socket_posix.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'base/sync_socket_posix.cc') 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 #include #include +#include #include #include "base/atomicops.h" @@ -98,10 +99,13 @@ size_t SyncSocket::Receive(void* buffer, size_t length) { } } -// 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 -- cgit v1.1