/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
auto BigBuffer::TryAllocBuffer(size_t aSize) -> Maybe<Storage> { if (aSize <= kShmemThreshold) { auto mem = UniqueFreePtr<uint8_t[]>{ reinterpret_cast<uint8_t*>(malloc(aSize))}; // Fallible! if (!mem) return {}; return Some(AsVariant(std::move(mem)));
}
RefPtr<SharedMemory> shmem = new SharedMemory();
size_t capacity = SharedMemory::PageAlignedSize(aSize); if (!shmem->Create(capacity) || !shmem->Map(capacity)) { return {};
} return Some(AsVariant(shmem));
}
} // namespace mozilla::ipc
void IPC::ParamTraits<mozilla::ipc::BigBuffer>::Write(MessageWriter* aWriter,
paramType&& aParam) { usingnamespace mozilla::ipc;
size_t size = std::exchange(aParam.mSize, 0); auto data = std::exchange(aParam.mData, BigBuffer::NoData());
if (isShmem) { if (!data.as<1>()->WriteHandle(aWriter)) {
aWriter->FatalError("Failed to write data shmem");
}
} else {
aWriter->WriteBytes(data.as<0>().get(), size);
}
}
bool IPC::ParamTraits<mozilla::ipc::BigBuffer>::Read(MessageReader* aReader,
paramType* aResult) { usingnamespace mozilla::ipc;
size_t size = 0; bool isShmem = false; if (!ReadParam(aReader, &size) || !ReadParam(aReader, &isShmem)) {
aReader->FatalError("Failed to read data size and format"); returnfalse;
}
if (isShmem) {
RefPtr<SharedMemory> shmem = new SharedMemory();
size_t capacity = SharedMemory::PageAlignedSize(size); if (!shmem->ReadHandle(aReader) || !shmem->Map(capacity)) {
aReader->FatalError("Failed to read data shmem"); returnfalse;
}
*aResult = BigBuffer(BigBuffer::Adopt{}, shmem, size); returntrue;
}
mozilla::UniqueFreePtr<uint8_t[]> buf{ reinterpret_cast<uint8_t*>(malloc(size))}; if (!buf) {
aReader->FatalError("Failed to allocate data buffer"); returnfalse;
} if (!aReader->ReadBytesInto(buf.get(), size)) {
aReader->FatalError("Failed to read data"); returnfalse;
}
*aResult = BigBuffer(BigBuffer::Adopt{}, buf.release(), size); returntrue;
}
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.