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

Unified Diff: mojo/public/cpp/bindings/lib/message.cc

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 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: mojo/public/cpp/bindings/lib/message.cc
diff --git a/mojo/public/cpp/bindings/lib/message.cc b/mojo/public/cpp/bindings/lib/message.cc
deleted file mode 100644
index d65ff4cd90107c0fa1577b8108c440556d80d722..0000000000000000000000000000000000000000
--- a/mojo/public/cpp/bindings/lib/message.cc
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/public/cpp/bindings/message.h"
-
-#include <stdlib.h>
-
-#include <algorithm>
-
-#include "mojo/public/cpp/environment/logging.h"
-
-namespace mojo {
-
-Message::Message() {
- Initialize();
-}
-
-Message::~Message() {
- FreeDataAndCloseHandles();
-}
-
-void Message::Reset() {
- FreeDataAndCloseHandles();
-
- handles_.clear();
- Initialize();
-}
-
-void Message::AllocData(uint32_t num_bytes) {
- MOJO_DCHECK(!data_);
- data_num_bytes_ = num_bytes;
- data_ = static_cast<internal::MessageData*>(calloc(num_bytes, 1));
-}
-
-void Message::AllocUninitializedData(uint32_t num_bytes) {
- MOJO_DCHECK(!data_);
- data_num_bytes_ = num_bytes;
- data_ = static_cast<internal::MessageData*>(malloc(num_bytes));
-}
-
-void Message::MoveTo(Message* destination) {
- MOJO_DCHECK(this != destination);
-
- destination->FreeDataAndCloseHandles();
-
- // No copy needed.
- destination->data_num_bytes_ = data_num_bytes_;
- destination->data_ = data_;
- std::swap(destination->handles_, handles_);
-
- handles_.clear();
- Initialize();
-}
-
-void Message::Initialize() {
- data_num_bytes_ = 0;
- data_ = nullptr;
-}
-
-void Message::FreeDataAndCloseHandles() {
- free(data_);
-
- for (std::vector<Handle>::iterator it = handles_.begin();
- it != handles_.end(); ++it) {
- if (it->is_valid())
- CloseRaw(*it);
- }
-}
-
-MojoResult ReadMessage(MessagePipeHandle handle, Message* message) {
- MOJO_DCHECK(handle.is_valid());
- MOJO_DCHECK(message);
- MOJO_DCHECK(message->handles()->empty());
- MOJO_DCHECK(message->data_num_bytes() == 0);
-
- uint32_t num_bytes = 0;
- uint32_t num_handles = 0;
- MojoResult rv = ReadMessageRaw(handle, nullptr, &num_bytes, nullptr,
- &num_handles, MOJO_READ_MESSAGE_FLAG_NONE);
- if (rv != MOJO_RESULT_RESOURCE_EXHAUSTED)
- return rv;
-
- message->AllocUninitializedData(num_bytes);
- message->mutable_handles()->resize(num_handles);
-
- uint32_t num_bytes_actual = num_bytes;
- uint32_t num_handles_actual = num_handles;
- rv = ReadMessageRaw(
- handle, message->mutable_data(), &num_bytes_actual,
- message->mutable_handles()->empty()
- ? nullptr
- : reinterpret_cast<MojoHandle*>(&message->mutable_handles()->front()),
- &num_handles_actual, MOJO_READ_MESSAGE_FLAG_NONE);
-
- MOJO_DCHECK(num_bytes == num_bytes_actual);
- MOJO_DCHECK(num_handles == num_handles_actual);
-
- return rv;
-}
-
-MojoResult ReadAndDispatchMessage(MessagePipeHandle handle,
- MessageReceiver* receiver,
- bool* receiver_result) {
- Message message;
- MojoResult rv = ReadMessage(handle, &message);
- if (receiver && rv == MOJO_RESULT_OK)
- *receiver_result = receiver->Accept(&message);
-
- return rv;
-}
-
-} // namespace mojo
« no previous file with comments | « mojo/public/cpp/bindings/lib/map_serialization_forward.h ('k') | mojo/public/cpp/bindings/lib/message_builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698