#socketcan #tokio #sockets #linux

tokio-socketcan

Asynchronous Linux SocketCAN sockets with tokio

6 releases

0.3.0 Feb 10, 2021
0.2.0 Nov 12, 2020
0.1.3 Feb 23, 2019
0.1.1 Jan 10, 2019
Download history 10/week @ 2020-12-25 32/week @ 2021-01-01 38/week @ 2021-01-08 44/week @ 2021-01-15 55/week @ 2021-01-22 24/week @ 2021-01-29 51/week @ 2021-02-05 50/week @ 2021-02-12 31/week @ 2021-02-19 37/week @ 2021-02-26 14/week @ 2021-03-05 49/week @ 2021-03-12 39/week @ 2021-03-19 47/week @ 2021-03-26 38/week @ 2021-04-02 45/week @ 2021-04-09

171 downloads per month
Used in 3 crates

MIT license

13KB
204 lines

crates.io badge documentation

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

Changelog

0.1.3

  • Fixed error events being effectively delayed in delivery until the next non-error arrived.

0.1.2

  • Added futures::sink::Sink implementation for the CANSocket

Dependencies

~5.5MB
~100K SLoC