You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: shared.rs
    path of file: ./repos/quilkin/benches
    
    the code of the file until where you have to start completion: #![allow(dead_code)]

pub use std::{
    net::{Ipv4Addr, SocketAddr, SocketAddrV4, UdpSocket},
    sync::{atomic, mpsc, Arc},
};

pub const READ_QUILKIN_PORT: u16 = 9001;
pub const WRITE_QUILKIN_PORT: u16 = 9002;

pub const NUMBER_OF_PACKETS: u16 = 10_000;

pub const PACKET_SIZES: &[usize] = &[
    254,  // Half IPv4 MTU.
    508,  // IPv4 MTU.
    1500, // Ethernet MTU.
];

pub fn make_socket(addr: SocketAddr) -> UdpSocket {
    let socket = UdpSocket::bind(addr).expect("failed to bind");
    // socket
    //     .set_read_timeout(Some(std::time::Duration::from_millis(1)))
    //     .expect("failed to set read timeout");
    socket
        .set_nonblocking(true)
        .expect("failed to set non-blocking");
    socket
}

#[inline]
pub fn spawn<F>(name: impl Into<String>, func: F) -> std::thread::JoinHandle<()>
where
    F: FnOnce() + Send + 'static,
{
    std::thread::Builder::new()
        .name(name.into())
        .spawn(func)
        .unwrap()
}

#[derive(Debug)]
pub enum ReadLoopMsg {
    #[allow(dead_code)]
    Blocked(PacketStats),
    Acked(PacketStats),
    Finished(PacketStats),
}

#[derive(Debug)]
pub struct PacketStats {
    /// Number of individual receives th
    
    pub fn write_all(&self, packet_count: u16) -> bool {
        let batch_size = batch_size(N);

        let mut packet_buf = [0xffu8; N];

        let mut send_batch = |sent: u16| -> u16 {
            let to_send = (packet_count - sent).min(batch_size);

            for seq in sent..sent + to_send {
                let b = seq.to_ne_bytes();
                packet_buf[0] = b[0];
                packet_buf[1] = b[1];

                self.socket.send_to(&packet_buf, self.destination).unwrap();
            }

            to_send
        };

        let mut sent_packets = 0;

        // Queue 2 batches at the beginning, giving the reader enough work to do
        // after the initial batch has been read
        sent_packets += send_batch(sent_packets);
        sent_packets += send_batch(sent_packets);

        let mut finished = false;
        while let Ok(msg) = self.rx.recv() {
            match msg {
                ReadLoopMsg::Blocked(ps) => {
                    panic!("reader blocked {ps:?}");
                }
                ReadLoopMsg::Acked(ps) => {
                    if sent_packets < packet_count {
                        assert!(sent_packets > ps.num_packets);
                        sent_packets += send_batch(sent_packets);
                    }
                }
                ReadLoopMsg::Finished(ps) => {
                    assert_eq!(sent_packets, ps.num_packets);
                    assert_eq!(ps.size_packets, N * packet_count as usize);
                    finished = true;
                    break;
                }
            }
        }

        finished
    }