#socket-can #tokio #sockets #linux #future #stream

tokio-socketcan

Asynchronous Linux SocketCAN sockets with tokio

7 releases

0.3.1 Nov 17, 2021
0.3.0 Feb 10, 2021
0.2.0 Nov 12, 2020
0.1.3 Feb 23, 2019
0.1.1 Jan 10, 2019

#565 in Asynchronous

Download history 361/week @ 2023-12-11 406/week @ 2023-12-18 8/week @ 2023-12-25 112/week @ 2024-01-01 285/week @ 2024-01-08 497/week @ 2024-01-15 436/week @ 2024-01-22 608/week @ 2024-01-29 565/week @ 2024-02-05 386/week @ 2024-02-12 389/week @ 2024-02-19 419/week @ 2024-02-26 439/week @ 2024-03-04 566/week @ 2024-03-11 395/week @ 2024-03-18 472/week @ 2024-03-25

1,873 downloads per month
Used in 4 crates

MIT license

14KB
201 lines

crates.io badge documentation Continuous integration

tokio-socketcan

SocketCAN support for tokio based on the socketcan crate.

Example echo server

use futures_util::stream::StreamExt;
use tokio_socketcan::{CANSocket, Error};

#[tokio::main]
async fn main() -> Result<(), Error> {
    let mut socket_rx = CANSocket::open("vcan0")?;
    let socket_tx = CANSocket::open("vcan0")?;
    while let Some(Ok(frame)) = socket_rx.next().await {
        socket_tx.write_frame(frame)?.await?;
    }
    Ok(())
}

Testing

Integrating the test into a CI system is non-trivial as it relies on a vcan0 virtual can device existing. Adding one to most linux systems is pretty easy with root access but attaching a vcan device to a container for CI seems difficult to find support for.

To run the tests locally, though, setup should be simple:

sudo modprobe vcan
sudo ip link add vcan0 type vcan
sudo ip link set vcan0 up
cargo test

Dependencies

~6–16MB
~190K SLoC