in src/agent/Agent.cc [285:319]
void Agent::pollControlPipe()
{
if (m_controlPipe->isClosed()) {
trace("Agent exiting (control pipe is closed)");
shutdown();
return;
}
while (true) {
uint64_t packetSize = 0;
const auto amt1 =
m_controlPipe->peek(&packetSize, sizeof(packetSize));
if (amt1 < sizeof(packetSize)) {
break;
}
ASSERT(packetSize >= sizeof(packetSize) && packetSize <= SIZE_MAX);
if (m_controlPipe->bytesAvailable() < packetSize) {
if (m_controlPipe->readBufferSize() < packetSize) {
m_controlPipe->setReadBufferSize(packetSize);
}
break;
}
std::vector<char> packetData;
packetData.resize(packetSize);
const auto amt2 = m_controlPipe->read(packetData.data(), packetSize);
ASSERT(amt2 == packetSize);
try {
ReadBuffer buffer(std::move(packetData));
buffer.getRawValue<uint64_t>(); // Discard the size.
handlePacket(buffer);
} catch (const ReadBuffer::DecodeError&) {
ASSERT(false && "Decode error");
}
}
}