forked from mirrors/gecko-dev
Bug 1465287 Part 9 - Allow copying IPDL messages, r=froydnj.
--HG-- extra : rebase_source : 25d5c75b5a5b07b545646535bd8da7b9fd9562dc
This commit is contained in:
parent
3354a96d8d
commit
3f2c401055
5 changed files with 40 additions and 0 deletions
|
|
@ -175,6 +175,14 @@ Pickle& Pickle::operator=(Pickle&& other) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
void Pickle::CopyFrom(const Pickle& other) {
|
||||
MOZ_ALWAYS_TRUE(buffers_.CopyFrom(other.buffers_));
|
||||
MOZ_ASSERT(other.header_ == reinterpret_cast<const Header*>(other.buffers_.Start()));
|
||||
|
||||
header_ = reinterpret_cast<Header*>(buffers_.Start());
|
||||
header_size_ = other.header_size_;
|
||||
}
|
||||
|
||||
bool Pickle::ReadBool(PickleIterator* iter, bool* result) const {
|
||||
DCHECK(iter);
|
||||
|
||||
|
|
|
|||
|
|
@ -78,6 +78,8 @@ class Pickle {
|
|||
|
||||
Pickle& operator=(Pickle&& other);
|
||||
|
||||
void CopyFrom(const Pickle& other);
|
||||
|
||||
// Returns the size of the Pickle's data.
|
||||
uint32_t size() const { return header_size_ + header_->payload_size; }
|
||||
|
||||
|
|
|
|||
|
|
@ -145,6 +145,12 @@ Message& Message::operator=(Message&& other) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
void Message::CopyFrom(const Message& other) {
|
||||
Pickle::CopyFrom(other);
|
||||
#if defined(OS_POSIX)
|
||||
file_descriptor_set_ = other.file_descriptor_set_;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(OS_POSIX)
|
||||
bool Message::WriteFileDescriptor(const base::FileDescriptor& descriptor) {
|
||||
|
|
|
|||
|
|
@ -213,6 +213,8 @@ class Message : public Pickle {
|
|||
Message& operator=(const Message& other) = delete;
|
||||
Message& operator=(Message&& other);
|
||||
|
||||
void CopyFrom(const Message& other);
|
||||
|
||||
// Helper method for the common case (default segmentCapacity, recording
|
||||
// the write latency of messages) of IPDL message creation. This helps
|
||||
// move the malloc and some of the parameter setting out of autogenerated
|
||||
|
|
|
|||
|
|
@ -135,6 +135,28 @@ class BufferList : private AllocPolicy
|
|||
return AllocateSegment(aInitialSize, aInitialCapacity);
|
||||
}
|
||||
|
||||
bool CopyFrom(const BufferList& aOther)
|
||||
{
|
||||
MOZ_ASSERT(mOwning);
|
||||
|
||||
Clear();
|
||||
|
||||
// We don't make an exact copy of aOther. Instead, create a single segment
|
||||
// with enough space to hold all data in aOther.
|
||||
if (!Init(aOther.mSize, (aOther.mSize + kSegmentAlignment - 1) & ~(kSegmentAlignment - 1))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t offset = 0;
|
||||
for (const Segment& segment : aOther.mSegments) {
|
||||
memcpy(Start() + offset, segment.mData, segment.mSize);
|
||||
offset += segment.mSize;
|
||||
}
|
||||
MOZ_ASSERT(offset == mSize);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Returns the sum of the sizes of all the buffers.
|
||||
size_t Size() const { return mSize; }
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue