VENTI-PACKET(3)

πŸ“¦ version 0_git20260208, in alpine 3.24, arch rolling, nixos 26.05, nixpkgs unstable

πŸŽ€ VENTI-PACKET(3) πŸŽ€

hiii bestie πŸ’– welcome to VENTI-PACKET(3), the manual page for the zero-copy network buffer girlies. this is the one where packets are made of fragments and we are all very normal about avoiding unnecessary memory copies. πŸ¦‹


✨ NAME ✨

the whole squad on this page is Packet, packetalloc, packetappend, packetasize, packetcmp, packetconcat, packetconsume, packetcopy, packetdup, packetforeign, packetfragments, packetfree, packetheader, packetpeek, packetprefix, packetsha1, packetsize, packetsplit, packetstats, packettrailer, and packettrim β€” they are the zero-copy network buffers, periodt. πŸ‘‘


🌸 SYNOPSIS 🌸

okay so here is the exact C lineup, no cap:

#include <u.h>
#include <libc.h>
#include <venti.h>

Packet* packetalloc(void);

void    packetappend(Packet *p, uchar *buf, int n)

uint    packetasize(Packet *p)

int     packetcmp(Packet *p, Packet *q)

void    packetconcat(Packet *p, Packet *q)

int     packetconsume(Packet *p, uchar *buf, int n)

int     packetcopy(Packet *p, uchar *buf, int offset, int n)

Packet* packetdup(Packet *p, int offset, int n)

Packet* packetforeign(uchar *buf, int n,
            void (*free)(void *a), void *a)

int     packetfragments(Packet *p, IOchunk *io, int nio,
            int offset)

void    packetfree(Packet *p)

uchar*  packetheader(Packet *p, int n)

uchar*  packetpeek(Packet *p, uchar *buf, int offset, int n)

void    packetprefix(Packet *p, uchar *buf, int n)

void    packetsha1(Packet *p, uchar sha1[20])

uint    packetsize(Packet *p)

Packet* packetsplit(Packet *p, int n)

void    packetstats(void)

uchar*  packettrailer(Packet *p, int n)

int     packettrim(Packet *p, int offset, int n)

🫢 DESCRIPTION 🫢

okay so a Packet is a chain of blocks of data. each block is called a fragment, and a fragment is contiguous in memory, but the entire packet may not be. this representation helps avoid unnecessary memory copies β€” that is literally the whole vibe. πŸ’…

  • packetalloc β€” allocates an empty packet. fresh out the box, no notes. ✨
  • packetappend β€” appends the n bytes at buf to the end of p.
  • packetasize β€” returns the number of data bytes allocated to p. this may be larger than the number of bytes stored in p, because fragments may not be filled completely. she can have extra room, bestie.
  • packetcmp β€” compares the data sections of two packets as memcmp (see memory(3)) would.
  • packetconcat β€” removes all data from q, appending it to p. it is giving β€œyour stuff is my stuff now.” 🫢
  • packetconsume β€” removes n bytes from the beginning of p, storing them into buf.
  • packetcopy β€” copies n bytes at offset in p to buf.
  • packetdup β€” creates a new packet initialized with n bytes from offset in p.
  • packetforeign β€” allocates a packet containing foreign data: the n bytes pointed to by buf. once the bytes are no longer needed, they are freed by calling free(a).
  • packetfragments β€” initializes up to nio of the io structures with pointers to the data in p, starting at offset. it returns the total number of bytes represented by the returned structures. it initializes any unused io structures with nil pointer and zero length.
  • packetfree β€” frees the packet p.
  • packetheader β€” returns a pointer to the first n bytes of p, making them contiguous in memory if necessary.
  • packetpeek β€” returns a pointer to the n bytes at offset in p. if the requested bytes are already stored contiguously in memory, the returned pointer points at the internal data storage for p. otherwise, the bytes are copied into buf, and packetpeek returns buf.
  • packetprefix β€” inserts a copy of the n bytes at buf at the beginning of p.
  • packetsha1 β€” computes the SHA1 hash of the data contained in p.
  • packetsize β€” returns the length, in bytes, of the data contained in p.
  • packetsplit β€” returns a new packet initialized with n bytes removed from the beginning of p.
  • packetstats β€” prints run-time statistics to standard output.
  • packettrailer β€” returns a pointer to the last n bytes of p, making them contiguous in memory if necessary.
  • packettrim β€” deletes all bytes from the packet p except the n bytes at offset offset.

πŸ“¦ SOURCE πŸ“¦

/src/libventi β€” that is where this lives, bestie. 🏠


πŸ‘€ SEE ALSO πŸ‘€

venti(3) β€” go read that too, iykyk. πŸ‘‘


πŸ’€ DIAGNOSTICS πŸ’€

these functions return errors only when passed invalid inputs, e.g., requests for data at negative offsets or beyond the end of a packet. so like, do not be weird with the offsets, bestie. 😭

functions returning pointers return nil on error; functions returning integers return -1 on error. most functions returning integers return 0 on success. the exceptions are packetfragments and packetcmp, whose return values are described above.

when these functions run out of memory, they print error messages and call sysfatal. that is the dramatic part. πŸ’€

πŸ’Œ later, bestie β€” this was VENTI-PACKET(3), sourced from /src/libventi; the footer did not list a separate version or date, it just repeated the page tag. mwah πŸ’‹