summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorcpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-04 22:53:22 +0000
committercpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-04 22:53:22 +0000
commitd8b65915b2181a863611254c3cefb966103386f3 (patch)
tree407ca5888d6e468854b78c701a4dac0fe811a6a0 /base
parent0baf8d2d5e43cbbc99700e0acf5eb0676c209972 (diff)
downloadchromium_src-d8b65915b2181a863611254c3cefb966103386f3.zip
chromium_src-d8b65915b2181a863611254c3cefb966103386f3.tar.gz
chromium_src-d8b65915b2181a863611254c3cefb966103386f3.tar.bz2
Add non-blocking peek for the syncsocket
- Windows only BUG=none TEST=unit test included Review URL: http://codereview.chromium.org/464020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33876 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/sync_socket.h6
-rw-r--r--base/sync_socket_posix.cc6
-rw-r--r--base/sync_socket_win.cc6
3 files changed, 18 insertions, 0 deletions
diff --git a/base/sync_socket.h b/base/sync_socket.h
index ad181ff..a44c445 100644
--- a/base/sync_socket.h
+++ b/base/sync_socket.h
@@ -51,6 +51,12 @@ class SyncSocket {
// Returns the number of bytes received, or 0 upon failure.
size_t Receive(void* buffer, size_t length);
+ // Returns the number of bytes available. If non-zero, Receive() will not
+ // not block when called. NOTE: Some implementations cannot reliably
+ // determine the number of bytes available so avoid using the returned
+ // size as a promise and simply test against zero.
+ size_t Peek();
+
// Extracts the contained handle. Used for transferring between
// processes.
Handle handle() const { return handle_; }
diff --git a/base/sync_socket_posix.cc b/base/sync_socket_posix.cc
index 35d53b2..5390c7d 100644
--- a/base/sync_socket_posix.cc
+++ b/base/sync_socket_posix.cc
@@ -98,4 +98,10 @@ size_t SyncSocket::Receive(void* buffer, size_t length) {
}
}
+// TODO(port). Some kind of select?
+size_t SyncSocket::Peek() {
+ NOTIMPLEMENTED();
+ return 0;
+}
+
} // namespace base
diff --git a/base/sync_socket_win.cc b/base/sync_socket_win.cc
index b591bb0..4e3c35f 100644
--- a/base/sync_socket_win.cc
+++ b/base/sync_socket_win.cc
@@ -141,4 +141,10 @@ size_t SyncSocket::Receive(void* buffer, size_t length) {
return count;
}
+size_t SyncSocket::Peek() {
+ DWORD available = 0;
+ PeekNamedPipe(handle_, NULL, 0, NULL, &available, NULL);
+ return available;
+}
+
} // namespace base