Doc fixes

pull/1/head
Alessandro Decina 3 years ago
parent 9f7b017d5d
commit be0b7bbd83

@ -58,7 +58,7 @@ use aya::Bpf;
use aya::programs::{CgroupSkb, CgroupSkbAttachType}; use aya::programs::{CgroupSkb, CgroupSkbAttachType};
// load the BPF code // load the BPF code
let bpf = Bpf::load_file("bpf.o")?; let mut bpf = Bpf::load_file("bpf.o")?;
// get the `ingress_filter` program compiled into `bpf.o`. // get the `ingress_filter` program compiled into `bpf.o`.
let ingress: &mut CgroupSkb = bpf.program_mut("ingress_filter")?.try_into()?; let ingress: &mut CgroupSkb = bpf.program_mut("ingress_filter")?.try_into()?;

@ -41,24 +41,22 @@ use crate::maps::{
/// # PerfBuf(#[from] aya::maps::perf::PerfBufferError), /// # PerfBuf(#[from] aya::maps::perf::PerfBufferError),
/// # } /// # }
/// # async fn try_main() -> Result<(), Error> { /// # async fn try_main() -> Result<(), Error> {
/// # use async_std::task;
/// # let bpf = aya::Bpf::load(&[], None)?; /// # let bpf = aya::Bpf::load(&[], None)?;
/// use aya::maps::perf::{AsyncPerfEventArray, PerfBufferError}; /// use aya::maps::perf::{AsyncPerfEventArray, PerfBufferError};
/// use aya::util::online_cpus; /// use aya::util::online_cpus;
/// use std::convert::TryFrom; /// use std::convert::TryFrom;
/// use futures::future; /// use futures::future;
/// use bytes::BytesMut; /// use bytes::BytesMut;
/// use tokio::task; // or async_std::task
/// ///
/// // try to convert the PERF_ARRAY map to an AsyncPerfEventArray /// // try to convert the PERF_ARRAY map to an AsyncPerfEventArray
/// let mut perf_array = AsyncPerfEventArray::try_from(bpf.map_mut("PERF_ARRAY")?)?; /// let mut perf_array = AsyncPerfEventArray::try_from(bpf.map_mut("PERF_ARRAY")?)?;
/// ///
/// let mut futs = Vec::new();
/// for cpu_id in online_cpus()? { /// for cpu_id in online_cpus()? {
/// // open a separate perf buffer for each cpu /// // open a separate perf buffer for each cpu
/// let mut buf = perf_array.open(cpu_id, None)?; /// let mut buf = perf_array.open(cpu_id, None)?;
/// ///
/// // process each perf buffer in a separate task /// // process each perf buffer in a separate task
/// // NOTE: use async_std::task::spawn with async-std and tokio::spawn with tokio
/// task::spawn(async move { /// task::spawn(async move {
/// let mut buffers = (0..10) /// let mut buffers = (0..10)
/// .map(|_| BytesMut::with_capacity(1024)) /// .map(|_| BytesMut::with_capacity(1024))

@ -14,6 +14,19 @@ use crate::{
}; };
/// A FIFO queue. /// A FIFO queue.
///
/// # Examples
/// ```no_run
/// # let bpf = aya::Bpf::load(&[], None)?;
/// use aya::maps::Queue;
/// use std::convert::TryFrom;
///
/// let mut queue = Queue::try_from(bpf.map_mut("ARRAY")?)?;
/// queue.push(42, 0)?;
/// queue.push(43, 0)?;
/// assert_eq!(queue.pop(0)?, 42);
/// # Ok::<(), aya::BpfError>(())
/// ```
#[doc(alias = "BPF_MAP_TYPE_QUEUE")] #[doc(alias = "BPF_MAP_TYPE_QUEUE")]
pub struct Queue<T: Deref<Target = Map>, V: Pod> { pub struct Queue<T: Deref<Target = Map>, V: Pod> {
inner: T, inner: T,
@ -80,19 +93,6 @@ impl<T: Deref<Target = Map> + DerefMut<Target = Map>, V: Pod> Queue<T, V> {
/// # Errors /// # Errors
/// ///
/// [`MapError::SyscallError`] if `bpf_map_update_elem` fails. /// [`MapError::SyscallError`] if `bpf_map_update_elem` fails.
///
/// # Examples
/// ```no_run
/// # let bpf = aya::Bpf::load(&[], None)?;
/// use aya::maps::Queue;
/// use std::convert::TryFrom;
///
/// let mut queue = Queue::try_from(bpf.map_mut("ARRAY")?)?;
/// queue.push(42, 0)?;
/// queue.push(43, 0)?;
/// assert_eq!(queue.pop(0)?, 42);
/// # Ok::<(), aya::BpfError>(())
/// ```
pub fn push(&mut self, value: V, flags: u64) -> Result<(), MapError> { pub fn push(&mut self, value: V, flags: u64) -> Result<(), MapError> {
let fd = self.inner.fd_or_err()?; let fd = self.inner.fd_or_err()?;
bpf_map_push_elem(fd, &value, flags).map_err(|(code, io_error)| { bpf_map_push_elem(fd, &value, flags).map_err(|(code, io_error)| {

@ -42,8 +42,7 @@ pub enum SocketFilterError {
/// # Bpf(#[from] aya::BpfError) /// # Bpf(#[from] aya::BpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[], None)?; /// # let mut bpf = aya::Bpf::load(&[], None)?;
/// use std::convert::{TryFrom, TryInto}; /// use std::convert::TryInto;
/// use std::io::Write;
/// use std::net::TcpStream; /// use std::net::TcpStream;
/// use std::os::unix::io::AsRawFd; /// use std::os::unix::io::AsRawFd;
/// use aya::programs::SocketFilter; /// use aya::programs::SocketFilter;

@ -37,7 +37,7 @@ pub enum TracePointError {
/// # Bpf(#[from] aya::BpfError) /// # Bpf(#[from] aya::BpfError)
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[], None)?; /// # let mut bpf = aya::Bpf::load(&[], None)?;
/// use std::convert::{TryFrom, TryInto}; /// use std::convert::TryInto;
/// use aya::programs::TracePoint; /// use aya::programs::TracePoint;
/// ///
/// let prog: &mut TracePoint = bpf.program_mut("trace_context_switch")?.try_into()?; /// let prog: &mut TracePoint = bpf.program_mut("trace_context_switch")?.try_into()?;

Loading…
Cancel
Save