Jiajie Chen e11bf06774 refactor: make connection handler own the socket (cancel-safe reads)
Fixes the tokio::select! cancel-safety concern: cancelling
UsbIpCommand::read_from_socket mid-command could drop already-consumed bytes
and desynchronize the protocol stream.

- handler now takes ownership of the socket (T instead of &mut T; requires
  Send + 'static), splits it, and runs a single background writer task that
  writes every response from an mpsc channel.
- The main loop only reads commands (never cancelled), so the protocol stream
  stays in sync.
- Route all responses (immediate and deferred) through the channel. Deferred
  completions are dropped if their seqnum was already cancelled by UNLINK.
- Update server() and the MockSocket-based tests accordingly (MockSocket now
  shares its output via Arc<Mutex<Vec<u8>>>).
2026-09-03 23:03:36 +08:00
2025-06-13 17:17:59 +08:00
2020-05-15 21:18:28 +08:00
2025-12-25 20:58:48 +08:00
2022-12-05 17:39:37 +08:00
2025-12-25 20:58:48 +08:00

usbip

Coverage Status crates.io

A Rust library to run a USB/IP server to simulate USB devices and share real USB devices over a network.

What is USB/IP?

USB/IP is a network protocol that allows USB devices to be shared between computers over a network. It enables:

  • Device simulation: Create virtual USB devices that can be accessed remotely
  • Device sharing: Share physical USB devices from one machine to another
  • Cross-platform: Works across different operating systems (Linux, etc.)

Installation

Prerequisites

Install Rust from the official documentation.

Building from source

git clone https://github.com/jiegec/usbip.git
cd usbip
cargo build --release

How to use

Examples

The examples/ directory contains three example programs:

  1. hid_keyboard: Simulate a HID keyboard that types something every second
  2. cdc_acm_serial: Simulate a CDC ACM serial device that receives a character every second
  3. host: Act as a USB/IP server, sharing physical devices from the host machine to remote clients

Running an example

cargo run --example hid_keyboard

Connecting from a USB/IP client

On the client machine (e.g. Linux with USB/IP support):

# List available devices
usbip list -r $remote_ip

# Attach to a device
usbip attach -r $remote_ip -b $bus_id

License

MIT License - see LICENSE file for details.

Description
A Rust library to run a USB/IP server
Readme MIT 512 KiB
Languages
Rust 82.9%
Shell 17.1%