A C++ library for creating usbip servers
✅ USBIP server: Platform-independent implementation via libusb (works wherever libusb is supported)
✅ Virtual HID devices: Create virtual USB devices on any platform without libusb dependency (seeexamples/
)
Contributions welcome! 🚀
USB communication and network I/O are both resource-intensive operations. This project implements a fully asynchronous architecture using:
- C++20 coroutines for network operations
- asio for asynchronous I/O
- libusb's async API for USB communications (physical devices)
Three dedicated threads ensure optimal performance:
- Network I/O thread: Runs
asio::io_context::run()
- USB transfer thread: Handles
libusb_handle_events()
- Worker thread pool: Processes device logic
Data flows through the system without blocking:
Network thread → libusb_submit_transfer → USB thread → Callback → Network thread
This architecture achieves high CPU efficiency by minimizing thread contention.
Virtual device handlers should:
- Avoid blocking the network thread
- Process requests in worker threads
- Submit responses via callbacks
📝 Language notice: Comments/logs primarily use Chinese for efficiency.
The code structure remains clear and approachable. PRs for English translations appreciated!
To implement custom USB devices:
- Define descriptors with
usbipdcpp::UsbDevice
- Implement device logic via
AbstDeviceHandler
subclass - Handle interface-specific operations with
VirtualInterfaceHandler
, and implements the logic of the endpoints inside the interface
For simple devices, use SimpleVirtualDeviceHandler
- it provides no-op implementations for standard requests.
Using libusb servers on Windows requires driver replacement:
- Use Zadig to install WinUSB driver
- Select target device (enable "List All Devices" if missing)
⚠️ WARNING: Replacing mouse/keyboard drivers may cause input loss
- After use, revert drivers via:
Win+X
→ Device Manager → Select device → Roll back driver
Due to this complexity, we recommend usbipd-win for physical devices on Windows.
This project is ideal for implementing virtual USB devices on Windows.
cmake -B build
cmake --build build
cmake --install build
find_package(usbipdcpp CONFIG REQUIRED)
target_link_libraries(main PRIVATE usbipdcpp::usbipdcpp)
# Or if want to use libusb server
find_package(usbipdcpp CONFIG REQUIRED COMPONENTS libusb)
target_link_libraries(main PRIVATE usbipdcpp::usbipdcpp usbipdcpp::usbipdcpp_libusb)
This project builds upon these foundational works: