mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Comms: Always use the inline buffer
PiperOrigin-RevId: 606974170 Change-Id: I5f384bfd1b0cd5fecf493162bc40f17860b5975b
This commit is contained in:
parent
4f93af65e6
commit
34f129dc51
@ -27,6 +27,7 @@
|
|||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@ -236,17 +237,19 @@ bool Comms::SendTLV(uint32_t tag, size_t length, const void* value) {
|
|||||||
.len = length,
|
.len = length,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (length + sizeof(tl) > kSendTLVTempBufferSize) {
|
const size_t inline_size =
|
||||||
if (!Send(&tl, sizeof(tl))) {
|
std::min(length, kSendTLVTempBufferSize - sizeof(tl));
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return Send(value, length);
|
|
||||||
}
|
|
||||||
uint8_t tlv[kSendTLVTempBufferSize];
|
uint8_t tlv[kSendTLVTempBufferSize];
|
||||||
memcpy(tlv, &tl, sizeof(tl));
|
memcpy(tlv, &tl, sizeof(tl));
|
||||||
memcpy(reinterpret_cast<uint8_t*>(tlv) + sizeof(tl), value, length);
|
memcpy(&tlv[sizeof(tl)], value, inline_size);
|
||||||
|
if (!Send(&tlv, sizeof(tl) + inline_size)) {
|
||||||
return Send(&tlv, sizeof(tl) + length);
|
return false;
|
||||||
|
}
|
||||||
|
if (inline_size < length) {
|
||||||
|
return Send(reinterpret_cast<const uint8_t*>(value) + inline_size,
|
||||||
|
length - inline_size);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Comms::RecvString(std::string* v) {
|
bool Comms::RecvString(std::string* v) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user