flags.set(0, true);
flags.set(1, true);
break;
- case PacketType::ISO:
- flags.set(0, direction == Direction::INCOMING);
- flags.set(1, true);
- break;
}
uint32_t length = packet.size() + /* type byte */ 1;
- btsnoop_packet_header_t header = {.length_original = htonl(length),
- .length_captured = htonl(length),
- .flags = htonl(static_cast<uint32_t>(flags.to_ulong())),
- .dropped_packets = 0,
- .timestamp = htonll(timestamp_us + BTSNOOP_EPOCH_DELTA),
- .type = static_cast<uint8_t>(type)};
- btsnoop_ostream_.write(reinterpret_cast<const char*>(&header), sizeof(btsnoop_packet_header_t));
- btsnoop_ostream_.write(reinterpret_cast<const char*>(packet.data()), packet.size());
- if (AlwaysFlush) btsnoop_ostream_.flush();
+ PacketHeaderType header = {.length_original = htonl(length),
+ .length_captured = htonl(length),
+ .flags = htonl(static_cast<uint32_t>(flags.to_ulong())),
+ .dropped_packets = 0,
+ .timestamp = htonll(timestamp_us + kBtSnoopEpochDelta),
+ .type = static_cast<uint8_t>(type)};
+ {
+ std::lock_guard<std::recursive_mutex> lock(file_mutex_);
+ packet_counter_++;
+ if (packet_counter_ > max_packets_per_file_) {
+ OpenNextSnoopLogFile();
+ }
+ if (!btsnoop_ostream_.write(reinterpret_cast<const char*>(&header), sizeof(PacketHeaderType))) {
+ LOG_ERROR("Failed to write packet header, error: \"%s\"", strerror(errno));
+ }
+ if (!btsnoop_ostream_.write(reinterpret_cast<const char*>(packet.data()), packet.size())) {
+ LOG_ERROR("Failed to write packet payload, error: \"%s\"", strerror(errno));
+ }
+ if (os::ParameterProvider::SnoopLogAlwaysFlush()) {
+ if (!btsnoop_ostream_.flush()) {
+ LOG_ERROR("Failed to flush, error: \"%s\"", strerror(errno));
+ }
+ }
+ }
}
void SnoopLogger::ListDependencies(ModuleList* list) {