summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsehr@google.com <sehr@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-06 19:45:08 +0000
committersehr@google.com <sehr@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-06 19:45:08 +0000
commit1e1f1a7eb400cfd9094262315fc03d6a4e13fa1b (patch)
tree7dc8af2ae8f949cc9114cb04931b2898be201315
parentde23ed934a0ed25ed0c371256e1f8f0355d465d2 (diff)
downloadchromium_src-1e1f1a7eb400cfd9094262315fc03d6a4e13fa1b.zip
chromium_src-1e1f1a7eb400cfd9094262315fc03d6a4e13fa1b.tar.gz
chromium_src-1e1f1a7eb400cfd9094262315fc03d6a4e13fa1b.tar.bz2
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
-rw-r--r--base/sync_socket_posix.cc10
-rw-r--r--ipc/sync_socket_unittest.cc7
2 files changed, 12 insertions, 5 deletions
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 @@ 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
diff --git a/ipc/sync_socket_unittest.cc b/ipc/sync_socket_unittest.cc
index 7710c09..c33d99a 100644
--- a/ipc/sync_socket_unittest.cc
+++ b/ipc/sync_socket_unittest.cc
@@ -189,14 +189,14 @@ class SyncSocketClientListener : public IPC::Channel::Listener {
// string as was written on the SyncSocket. These are compared
// and a shutdown message is sent back to the server.
void OnMsgClassResponse(const std::string& str) {
-#if defined(OS_WIN)
// We rely on the order of sync_socket.Send() and chan_->Send() in
// the SyncSocketServerListener object.
EXPECT_EQ(kHelloStringLength, socket_->Peek());
-#endif
char buf[kHelloStringLength];
socket_->Receive(static_cast<void*>(buf), kHelloStringLength);
EXPECT_EQ(strcmp(str.c_str(), buf), 0);
+ // After receiving from the socket there should be no bytes left.
+ EXPECT_EQ(0, socket_->Peek());
IPC::Message* msg = new MsgClassShutdown();
EXPECT_NE(msg, reinterpret_cast<IPC::Message*>(NULL));
EXPECT_TRUE(chan_->Send(msg));
@@ -221,6 +221,9 @@ TEST_F(SyncSocketTest, SanityTest) {
// Create a pair of SyncSockets.
base::SyncSocket* pair[2];
base::SyncSocket::CreatePair(pair);
+ // Immediately after creation there should be no pending bytes.
+ EXPECT_EQ(0, pair[0]->Peek());
+ EXPECT_EQ(0, pair[1]->Peek());
base::SyncSocket::Handle target_handle;
// Connect the channel and listener.
ASSERT_TRUE(chan.Connect());