Skip to content

/dev/net/tun not writable #594

Open
Open
@lparam

Description

@lparam

not-writable-demo.tar.gz

steps to reproduce

  1. cargo build; sudo ./target/debug/demo
  2. wait a few seconds
  3. press any key in the same terminal of the demo program

key code

        loop {
            select! {
                r = tun_file.read(&mut tun_buf).fuse() => match r {
                    Ok(n) => {
                        println!("read {} bytes {:?} from tun", n, &tun_buf[..n]);
                    }
                    Err(e) => {
                        println!("read error: {}", e);
                    }
                },
                line = lines_from_stdin.next().fuse() => match line {
                    Some(line) => {
                        let line = line?;
                        println!("line: {}", line);
                        let buf: [u8; 32] = [0x45, 0x00, 0x00, 0x20, 0x91, 0xb3, 0x40, 0x00, 0x40, 0x11, 0x8d, 0x17, 0x0a, 0x00, 0x05, 0x01, 0x0a, 0x00, 0x05, 0x03, 0x83, 0x0d, 0x1f, 0x90, 0x00, 0x0c, 0x7c, 0xc9, 0x61, 0x62, 0x63, 0x0a];
                        match tun_file.write(&buf).await { // block here, not writable
                            Ok(n) => {
                                println!("write {} bytes to tun", n);
                            },
                            Err(e) => {
                                println!("write error: {}", e);
                            }
                        }
                        // the codes below works fine.
                        /*let n = match unsafe { libc::write(tun_file.as_raw_fd(), buf.as_ptr() as _, buf.len() as _) } {
                            -1 => 0,
                            n => n,
                        };
                        println!("write {} bytes to tun", n);*/
                    }
                    None => break,
                }
            }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions