void put_pkt(buf_ptr &buf) { size_t rank; size_t block = super::rlnc_hdr_block(buf); if (!validate_block(block)) { if (m_late_pkts++ % 5 == 1) send_ack(block, base::m_coder->symbols()); return; } assert(buf->data_val() % 4u == 0); assert(buf->data_len() >= super::rlnc_symbol_size()); rank = base::m_coder->rank(); super::rlnc_hdr_del(buf); base::m_coder->decode(buf->head()); assert(base::m_coder->rank() <= base::m_coder->remote_rank()); if (base::m_coder->rank() == rank) { ++m_linear; ++m_linear_block; ++m_linear_count; } else { m_linear = 0; } if (m_linear < 50) return; std::cout << "emergency ack " << base::m_coder->rank() << std::endl; send_ack(super::rlnc_hdr_block(), base::m_coder->rank()); }
void get_pkt(buf_ptr &buf) { size_t size = base::m_coder->symbol_size(); memcpy(buf->head(), base::m_coder->symbol(m_decoded++), size); buf->trim(size); ++m_decoded_count; }
void put_pkt(buf_ptr &buf) { assert(buf->head_val() % 4u == 0); sak::const_storage symbol(buf->head(), buf->len()); base::m_coder->set_symbol(base::m_coder->symbols_initialized(), symbol); super::increase_budget(); }
bool write_pkt(buf_ptr &buf) { int res = sendto(fd(), buf->head(), buf->len(), 0, sa_send(), sa_send_len()); if (res > 0) { buf->pull(res); return true; } if (res < 0 && (errno == EAGAIN || errno == ENOBUFS)) return false; throw std::system_error(errno, std::system_category(), "unable to write packet"); }
bool read_pkt(buf_ptr &buf, size_t len, size_t offset = 0) { int res = recvfrom(fd(), buf->head() + offset, len, 0, sa_recv(), sa_recv_len()); if (res > 0) { buf->push(res); return true; } if (res == 0) throw std::runtime_error("connection closed"); if (res < 0 && errno == EAGAIN) return false; throw std::system_error(errno, std::system_category(), "unable to recv packet"); }
bool write_pkt(buf_ptr &buf) { int len = buf->len(); int res = write(m_fd, buf->head(), buf->len()); if (res == len) return true; if (res > 0) { std::cout << "incomplete write: " << res << std::endl; throw std::runtime_error("incomplete write"); } if (res == 0) return false; if (res < 0 && errno == EAGAIN) return false; throw std::system_error(errno, std::system_category(), "unable to write pkt"); }
bool compare_source(buf_ptr &buf, uint8_t *addr) { return addr && memcmp(hdr_source(buf->head()), addr, ETH_ALEN) == 0; }