[api] Move HELPER_LOG_PACKETS logging to call sites before fast path

LOG_PACKET_SENDING was in write_raw_iov_ which is only called on
the slow path. Moved to write_protobuf_packet and write_protobuf_messages
so all packets are logged regardless of which write path is taken.
This commit is contained in:
J. Nick Koston
2026-03-29 13:52:29 -10:00
parent 1c1ddf463b
commit 2e1d6e4d58
3 changed files with 12 additions and 6 deletions
@@ -123,12 +123,6 @@ APIError APIFrameHelper::write_raw_buf_(const void *data, uint16_t len, ssize_t
// or directly from cold paths (handshake, error handling).
// sent == -1 means either the fast path write returned -1, or there was overflow backlog.
APIError APIFrameHelper::write_raw_iov_(const struct iovec *iov, int iovcnt, uint16_t total_write_len, ssize_t sent) {
#ifdef HELPER_LOG_PACKETS
for (int i = 0; i < iovcnt; i++) {
LOG_PACKET_SENDING(reinterpret_cast<uint8_t *>(iov[i].iov_base), iov[i].iov_len);
}
#endif
if (sent == -1) {
// Either the fast path write returned -1, or we were called directly (cold path)
if (!this->overflow_buf_.empty()) {
@@ -505,6 +505,7 @@ APIError APINoiseFrameHelper::write_protobuf_packet(uint8_t type, ProtoWriteBuff
if (aerr != APIError::OK)
return aerr;
// buf_start and iov.iov_base point to the same location
LOG_PACKET_SENDING(buf_start, iov.iov_len);
return this->write_raw_fast_buf_(buf_start, static_cast<uint16_t>(iov.iov_len));
}
@@ -528,6 +529,11 @@ APIError APINoiseFrameHelper::write_protobuf_messages(ProtoWriteBuffer buffer, s
total_write_len += iov.iov_len;
}
#ifdef HELPER_LOG_PACKETS
for (const auto &iov : iovs) {
LOG_PACKET_SENDING(reinterpret_cast<uint8_t *>(iov.iov_base), iov.iov_len);
}
#endif
return this->write_raw_fast_iov_(iovs.data(), iovs.size(), total_write_len);
}
@@ -292,6 +292,7 @@ APIError APIPlaintextFrameHelper::write_protobuf_packet(uint8_t type, ProtoWrite
uint8_t *msg_start = write_plaintext_header(buffer_data, msg, frame_header_padding_);
uint8_t msg_header_len = static_cast<uint8_t>(buffer_data + frame_header_padding_ - msg_start);
uint16_t msg_len = static_cast<uint16_t>(msg_header_len + msg.payload_size);
LOG_PACKET_SENDING(msg_start, msg_len);
return this->write_raw_fast_buf_(msg_start, msg_len);
}
@@ -315,6 +316,11 @@ APIError APIPlaintextFrameHelper::write_protobuf_messages(ProtoWriteBuffer buffe
total_write_len += msg_len;
}
#ifdef HELPER_LOG_PACKETS
for (const auto &iov : iovs) {
LOG_PACKET_SENDING(reinterpret_cast<uint8_t *>(iov.iov_base), iov.iov_len);
}
#endif
return this->write_raw_fast_iov_(iovs.data(), iovs.size(), total_write_len);
}