Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Unified Diff: media/audio/async_socket_io_handler.h

Issue 10697069: Move the callback out of the Read method and into Initialize to make Read loops simpler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix expectations for the synchronous test Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/audio/async_socket_io_handler.h
diff --git a/media/audio/async_socket_io_handler.h b/media/audio/async_socket_io_handler.h
index 0bbb5c17fd905eb00461077cb5112d58d9219c7d..d17e3d3d72f1d3c558cd4f4240365a8a0a5a9dfb 100644
--- a/media/audio/async_socket_io_handler.h
+++ b/media/audio/async_socket_io_handler.h
@@ -30,18 +30,21 @@ typedef MessageLoopForIO::Watcher MessageLoopIOHandler;
// public:
// SocketReader(base::CancelableSyncSocket* socket)
// : socket_(socket), buffer_() {
-// io_handler.Initialize(socket_->handle());
+// io_handler.Initialize(socket_->handle(),
+// base::Bind(&SocketReader::OnDataAvailable,
+// base::Unretained(this));
// }
//
// void AsyncRead() {
-// CHECK(io_handler.Read(&buffer_[0], sizeof(buffer_),
-// base::Bind(&SocketReader::OnDataAvailable,
-// base::Unretained(this)));
+// CHECK(io_handler.Read(&buffer_[0], sizeof(buffer_)));
// }
//
// private:
// void OnDataAvailable(int bytes_read) {
-// ProcessData(&buffer_[0], bytes_read);
+// if (ProcessData(&buffer_[0], bytes_read)) {
+// // Issue another read.
+// CHECK(io_handler.Read(&buffer_[0], sizeof(buffer_)));
+// }
// }
//
// media::AsyncSocketIoHandler io_handler;
@@ -56,21 +59,22 @@ class MEDIA_EXPORT AsyncSocketIoHandler
AsyncSocketIoHandler();
virtual ~AsyncSocketIoHandler();
- // Initializes the AsyncSocketIoHandler by hooking it up to the current
- // thread's message loop (must be TYPE_IO), to do async reads from the socket
- // on the current thread.
- bool Initialize(base::SyncSocket::Handle socket);
-
// Type definition for the callback. The parameter tells how many
// bytes were read and is 0 if an error occurred.
typedef base::Callback<void(int)> ReadCompleteCallback;
+ // Initializes the AsyncSocketIoHandler by hooking it up to the current
+ // thread's message loop (must be TYPE_IO), to do async reads from the socket
+ // on the current thread. The |callback| will be invoked whenever a Read()
+ // has completed.
+ bool Initialize(base::SyncSocket::Handle socket,
+ const ReadCompleteCallback& callback);
+
// Attempts to read from the socket. The return value will be |false|
// if an error occurred and |true| if data was read or a pending read
- // was issued. Regardless of async or sync operation, the callback will
- // be called when data is available.
- bool Read(char* buffer, int buffer_len,
- const ReadCompleteCallback& callback);
+ // was issued. Regardless of async or sync operation, the
+ // ReadCompleteCallback (see above) will be called when data is available.
+ bool Read(char* buffer, int buffer_len);
private:
#if defined(OS_WIN)
@@ -89,6 +93,7 @@ class MEDIA_EXPORT AsyncSocketIoHandler
base::SyncSocket::Handle socket_;
#if defined(OS_WIN)
MessageLoopForIO::IOContext* context_;
+ bool is_pending_;
#elif defined(OS_POSIX)
MessageLoopForIO::FileDescriptorWatcher socket_watcher_;
// |pending_buffer_| and |pending_buffer_len_| are valid only between
« no previous file with comments | « no previous file | media/audio/async_socket_io_handler_posix.cc » ('j') | media/audio/async_socket_io_handler_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698