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

Unified Diff: mojo/public/bindings/lib/connector.cc

Issue 65043004: Add better handle tracking, and optimize Connector::Accept. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update per review feedback Created 7 years, 1 month 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
« no previous file with comments | « mojo/public/bindings/lib/connector.h ('k') | mojo/public/bindings/lib/message.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/bindings/lib/connector.cc
diff --git a/mojo/public/bindings/lib/connector.cc b/mojo/public/bindings/lib/connector.cc
index 3bb04f9fff9c969f54cb69fd19b268cbe1c43f68..f72bca36ab7104e9c5e8649be2d50378111b9356 100644
--- a/mojo/public/bindings/lib/connector.cc
+++ b/mojo/public/bindings/lib/connector.cc
@@ -37,8 +37,15 @@ bool Connector::Accept(Message* message) {
if (error_)
return false;
- write_queue_.Push(message);
- WriteMore();
+ bool wait_to_write;
+ WriteOne(message, &wait_to_write);
+
+ if (wait_to_write) {
+ WaitToWriteMore();
+ if (!error_)
+ write_queue_.Push(message);
+ }
+
return !error_;
}
@@ -111,24 +118,37 @@ void Connector::ReadMore() {
}
void Connector::WriteMore() {
- while (!write_queue_.IsEmpty()) {
- const Message* message = write_queue_.Peek();
-
- MojoResult rv = WriteMessage(message_pipe_,
- message->data,
- message->data->header.num_bytes,
- message->handles.data(),
- message->handles.size(),
- MOJO_WRITE_MESSAGE_FLAG_NONE);
- if (rv == MOJO_RESULT_OK) {
- // TODO(darin): Handles were successfully transferred, and so we need
- // to take care not to Close them here.
- write_queue_.Pop();
- continue; // Write another message.
- }
+ while (!error_ && !write_queue_.IsEmpty()) {
+ Message* message = write_queue_.Peek();
+
+ bool wait_to_write;
+ WriteOne(message, &wait_to_write);
+ if (wait_to_write)
+ break;
+
+ write_queue_.Pop();
+ }
+}
+void Connector::WriteOne(Message* message, bool* wait_to_write) {
+ // TODO(darin): WriteMessage will eventually start generating an error that
+ // it cannot accept more data. In that case, we'll need to wait on the pipe
+ // to determine when we can try writing again. This flag will be set to true
+ // in that case.
+ *wait_to_write = false;
+
+ MojoResult rv = WriteMessage(message_pipe_,
+ message->data,
+ message->data->header.num_bytes,
+ message->handles.data(),
+ static_cast<uint32_t>(message->handles.size()),
+ MOJO_WRITE_MESSAGE_FLAG_NONE);
+ if (rv == MOJO_RESULT_OK) {
+ // The handles were successfully transferred, so we don't need the message
+ // to track their lifetime any longer.
+ message->handles.clear();
+ } else {
error_ = true;
- break;
}
}
« no previous file with comments | « mojo/public/bindings/lib/connector.h ('k') | mojo/public/bindings/lib/message.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698