Loading system/vendor_libs/test_vendor_lib/model/devices/link_layer_socket_device.cc +22 −20 Original line number Diff line number Diff line Loading @@ -27,38 +27,40 @@ using std::vector; namespace test_vendor_lib { LinkLayerSocketDevice::LinkLayerSocketDevice(int socket_fd, Phy::Type phy_type) : socket_(socket_fd), phy_type_(phy_type) {} : socket_(socket_fd), phy_type_(phy_type), size_bytes_(std::make_shared<std::vector<uint8_t>>(kSizeBytes)) {} void LinkLayerSocketDevice::TimerTick() { if (bytes_left_ == 0) { auto packet_size = std::make_shared<std::vector<uint8_t>>(kSizeBytes); size_t bytes_received = socket_.TryReceive(kSizeBytes, packet_size->data()); if (bytes_received == 0) { if (receiving_size_) { size_t bytes_received = socket_.TryReceive(kSizeBytes, size_bytes_->data() + offset_); if (bytes_received < bytes_left_) { bytes_left_ -= bytes_received; offset_ += bytes_received; return; } ASSERT_LOG(bytes_received == kSizeBytes, "bytes_received == %d", static_cast<int>(bytes_received)); bluetooth::packet::PacketView<bluetooth::packet::kLittleEndian> size( {bluetooth::packet::View(packet_size, 0, kSizeBytes)}); {bluetooth::packet::View(size_bytes_, 0, kSizeBytes)}); bytes_left_ = size.begin().extract<uint32_t>(); received_ = std::make_shared<std::vector<uint8_t>>(bytes_left_); offset_ = 0; receiving_size_ = false; } size_t bytes_received = socket_.TryReceive(bytes_left_, received_->data() + offset_); if (bytes_received == 0) { return; } if (bytes_received < bytes_left_) { bytes_left_ -= bytes_received; offset_ += bytes_received; if (bytes_left_ == 0) { bluetooth::packet::PacketView<bluetooth::packet::kLittleEndian> packet_view( received_); auto packet = model::packets::LinkLayerPacketView::Create(packet_view); return; } bytes_left_ = kSizeBytes; offset_ = 0; receiving_size_ = true; auto packet = model::packets::LinkLayerPacketView::Create( bluetooth::packet::PacketView<bluetooth::packet::kLittleEndian>( received_)); ASSERT(packet.IsValid()); SendLinkLayerPacket(packet, phy_type_); offset_ = 0; received_.reset(); } } void LinkLayerSocketDevice::IncomingPacket( Loading system/vendor_libs/test_vendor_lib/model/devices/link_layer_socket_device.h +4 −2 Original line number Diff line number Diff line Loading @@ -52,8 +52,10 @@ class LinkLayerSocketDevice : public Device { private: net::PolledSocket socket_; Phy::Type phy_type_; size_t bytes_left_{0}; size_t offset_{}; bool receiving_size_{true}; size_t bytes_left_{kSizeBytes}; size_t offset_{0}; std::shared_ptr<std::vector<uint8_t>> size_bytes_; std::shared_ptr<std::vector<uint8_t>> received_; std::vector<model::packets::LinkLayerPacketView> packet_queue_; }; Loading Loading
system/vendor_libs/test_vendor_lib/model/devices/link_layer_socket_device.cc +22 −20 Original line number Diff line number Diff line Loading @@ -27,38 +27,40 @@ using std::vector; namespace test_vendor_lib { LinkLayerSocketDevice::LinkLayerSocketDevice(int socket_fd, Phy::Type phy_type) : socket_(socket_fd), phy_type_(phy_type) {} : socket_(socket_fd), phy_type_(phy_type), size_bytes_(std::make_shared<std::vector<uint8_t>>(kSizeBytes)) {} void LinkLayerSocketDevice::TimerTick() { if (bytes_left_ == 0) { auto packet_size = std::make_shared<std::vector<uint8_t>>(kSizeBytes); size_t bytes_received = socket_.TryReceive(kSizeBytes, packet_size->data()); if (bytes_received == 0) { if (receiving_size_) { size_t bytes_received = socket_.TryReceive(kSizeBytes, size_bytes_->data() + offset_); if (bytes_received < bytes_left_) { bytes_left_ -= bytes_received; offset_ += bytes_received; return; } ASSERT_LOG(bytes_received == kSizeBytes, "bytes_received == %d", static_cast<int>(bytes_received)); bluetooth::packet::PacketView<bluetooth::packet::kLittleEndian> size( {bluetooth::packet::View(packet_size, 0, kSizeBytes)}); {bluetooth::packet::View(size_bytes_, 0, kSizeBytes)}); bytes_left_ = size.begin().extract<uint32_t>(); received_ = std::make_shared<std::vector<uint8_t>>(bytes_left_); offset_ = 0; receiving_size_ = false; } size_t bytes_received = socket_.TryReceive(bytes_left_, received_->data() + offset_); if (bytes_received == 0) { return; } if (bytes_received < bytes_left_) { bytes_left_ -= bytes_received; offset_ += bytes_received; if (bytes_left_ == 0) { bluetooth::packet::PacketView<bluetooth::packet::kLittleEndian> packet_view( received_); auto packet = model::packets::LinkLayerPacketView::Create(packet_view); return; } bytes_left_ = kSizeBytes; offset_ = 0; receiving_size_ = true; auto packet = model::packets::LinkLayerPacketView::Create( bluetooth::packet::PacketView<bluetooth::packet::kLittleEndian>( received_)); ASSERT(packet.IsValid()); SendLinkLayerPacket(packet, phy_type_); offset_ = 0; received_.reset(); } } void LinkLayerSocketDevice::IncomingPacket( Loading
system/vendor_libs/test_vendor_lib/model/devices/link_layer_socket_device.h +4 −2 Original line number Diff line number Diff line Loading @@ -52,8 +52,10 @@ class LinkLayerSocketDevice : public Device { private: net::PolledSocket socket_; Phy::Type phy_type_; size_t bytes_left_{0}; size_t offset_{}; bool receiving_size_{true}; size_t bytes_left_{kSizeBytes}; size_t offset_{0}; std::shared_ptr<std::vector<uint8_t>> size_bytes_; std::shared_ptr<std::vector<uint8_t>> received_; std::vector<model::packets::LinkLayerPacketView> packet_queue_; }; Loading