1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! # vma-socket
//!
//! A flexible high-level Rust API for TCP/UDP sockets leveraging Mellanox/NVIDIA VMA
//! (Messaging Accelerator) for low-latency networking.
//!
//! This library provides clean, safe Rust wrappers around the VMA C library, allowing
//! developers to use the performance benefits of VMA without dealing with the complexity
//! of direct C FFI calls.
//!
//! ## Features
//!
//! - Simple, idiomatic Rust API for UDP and TCP sockets
//! - Configurable performance options to match application requirements
//! - Timeout handling and error management in Rust style
//! - Memory safety through proper Rust abstractions
//!
//! ## UDP Example
//!
//! ```rust,no_run
//! use vma_socket::udp::VmaUdpSocket;
//!
//! fn udp_example() -> Result<(), String> {
//! // Create a socket with default options
//! let mut socket = VmaUdpSocket::new()?;
//!
//! // Bind to a port
//! socket.bind("0.0.0.0", 5001)?;
//!
//! // Receive data with timeout
//! let mut buffer = vec![0u8; 4096];
//! match socket.recv_from(&mut buffer, Some(100_000_000)) { // 100ms timeout
//! Some(packet) => {
//! println!("Received {} bytes", packet.data.len());
//!
//! // Reply to sender
//! let ip = packet.src_addr.ip().to_string();
//! let port = packet.src_addr.port();
//! socket.send_to(&packet.data, ip, port)?;
//! },
//! None => println!("No data received (timeout)"),
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ## TCP Example
//!
//! ```rust,no_run
//! use vma_socket::tcp::VmaTcpSocket;
//!
//! fn tcp_server_example() -> Result<(), String> {
//! // Create a TCP socket
//! let mut socket = VmaTcpSocket::new()?;
//!
//! // Bind and listen
//! socket.bind("0.0.0.0", 5002)?;
//! socket.listen(10)?;
//!
//! // Accept client connections
//! if let Some(mut client) = socket.accept(Some(1_000_000_000))? {
//! // Receive and echo data
//! let mut buffer = vec![0u8; 1024];
//! let received = client.recv(&mut buffer, Some(100_000_000))?; // 100ms timeout
//! if received > 0 {
//! client.send(&buffer[0..received])?;
//! }
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ## Running with VMA
//!
//! To utilize VMA acceleration, run your application with the VMA library preloaded:
//!
//! ```bash
//! LD_PRELOAD=/usr/lib64/libvma.so.x.x.x ./your_application
//! ```
//!
//! ## Module Structure
//!
//! - [`udp`]: UDP socket implementation
//! - [`tcp`]: TCP socket implementation
//! - [`common`]: Shared types and configuration options
/// UDP socket implementation
/// TCP socket implementation
/// Common types and utilities