VENTI-PACKET(3)
π 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 thenbytes atbufto the end ofp.packetasizeβ returns the number of data bytes allocated top. this may be larger than the number of bytes stored inp, because fragments may not be filled completely. she can have extra room, bestie.packetcmpβ compares the data sections of two packets asmemcmp(seememory(3)) would.packetconcatβ removes all data fromq, appending it top. it is giving βyour stuff is my stuff now.β π«Άpacketconsumeβ removesnbytes from the beginning ofp, storing them intobuf.packetcopyβ copiesnbytes atoffsetinptobuf.packetdupβ creates a new packet initialized withnbytes fromoffsetinp.packetforeignβ allocates a packet containingforeigndata: thenbytes pointed to bybuf. once the bytes are no longer needed, they are freed by callingfree(a).packetfragmentsβ initializes up tonioof the io structures with pointers to the data inp, starting atoffset. it returns the total number of bytes represented by the returned structures. it initializes any unused io structures withnilpointer and zero length.packetfreeβ frees the packetp.packetheaderβ returns a pointer to the firstnbytes ofp, making them contiguous in memory if necessary.packetpeekβ returns a pointer to thenbytes atoffsetinp. if the requested bytes are already stored contiguously in memory, the returned pointer points at the internal data storage forp. otherwise, the bytes are copied intobuf, andpacketpeekreturnsbuf.packetprefixβ inserts a copy of thenbytes atbufat the beginning ofp.packetsha1β computes the SHA1 hash of the data contained inp.packetsizeβ returns the length, in bytes, of the data contained inp.packetsplitβ returns a new packet initialized withnbytes removed from the beginning ofp.packetstatsβ prints run-time statistics to standard output.packettrailerβ returns a pointer to the lastnbytes ofp, making them contiguous in memory if necessary.packettrimβ deletes all bytes from the packetpexcept thenbytes at offsetoffset.
π¦ 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 wasVENTI-PACKET(3), sourced from/src/libventi; the footer did not list a separate version or date, it just repeated the page tag. mwah π
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms