diff --git a/src/dummy_link/DummyLink.cpp b/src/dummy_link/DummyLink.cpp index c82c41fb..2b3fefef 100644 --- a/src/dummy_link/DummyLink.cpp +++ b/src/dummy_link/DummyLink.cpp @@ -71,17 +71,6 @@ static void send_data(int fd,const std::string& name,const uint8_t* data,int dat static constexpr auto MAX_MTU_INCLUDING_HEADER=2000; -static std::shared_ptr> read_data(int fd){ - auto buff=std::make_shared>(); - buff->resize(MAX_MTU_INCLUDING_HEADER); - auto size=recvfrom(fd, buff->data(), buff->size(), MSG_DONTWAIT, NULL, NULL); - if(size>0){ - buff->resize(size); - return buff; - } - return nullptr; -} - DummyLink::DummyLink(bool is_air):m_is_air(is_air) { if(m_is_air){ m_fn_tx="air"; @@ -101,6 +90,7 @@ DummyLink::DummyLink(bool is_air):m_is_air(is_air) { } DummyLink::~DummyLink() { + close(m_fd_rx); m_keep_receiving= false; m_receive_thread->join(); m_receive_thread= nullptr; @@ -124,9 +114,13 @@ std::shared_ptr> DummyLink::rx_radiotap() { } void DummyLink::loop_rx() { + auto read_buffer=std::make_shared>(MAX_MTU_INCLUDING_HEADER); while (m_keep_receiving){ - auto packet= read_data(m_fd_rx); - if(packet!= nullptr){ + //auto packet= read_data(m_fd_rx); + //auto size=recvfrom(fd, buff->data(), buff->size(), MSG_DONTWAIT, NULL, NULL); + auto size = recv(m_fd_rx, read_buffer->data(), read_buffer->size(), MSG_WAITALL); + if(size>0){ + auto packet=std::make_shared>(read_buffer->data(),read_buffer->data()+size); //std::cout<<"Got packet"<size()<(); item->buff=packet;