VENTI-CONN(3)

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

πŸ’– VENTI-CONN(3) πŸ’–

okay so welcome to VENTI-CONN(3), straight out of the Library Functions Manual, section 3 (the library-functions section, iykyk). this is the whole Venti network-connection situation and honestly? it's giving infrastructure. let's get into it 🫢


✨ NAME ✨

VtConn, vtconn, vtdial, vtfreeconn, vtsend, vtrecv, vtversion, vtdebug, vthangup β€” all the little guys that handle Venti network connections πŸ’…

πŸŽ€ SYNOPSIS πŸŽ€

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

typedef struct VtConn {
    int  debug;
    char *version;
    char *uid;
    char *sid;
    char addr[256];
    ...
} VtConn;

VtConn*    vtconn(int infd, int outfd)

int        vtreconn(VtConn *z, int infd, int outfd)

VtConn*    vtdial(char *addr)

int        vtredial(VtConn *z, char *addr)

int        vtversion(VtConn *z)

int        vtsend(VtConn *z, Packet *p)

Packet*    vtrecv(VtConn *z)

void       vtrecvproc(void *z)

void       vtsendproc(void *z)

void       vtdebug(VtConn *z, char *fmt, ...)

void       vthangup(VtConn *z)

void       vtfreeconn(VtConn *z)

extern int chattyventi;/* default 0 */

like, look at all those little functions. they're a family. 🧚

🌸 DESCRIPTION 🌸

a VtConn structure is literally just a representation of a connection β€” to a Venti server when a client is using it, or to a client when a server is using it. main character struct energy honestly. πŸ‘‘

it's got these user-visible fields, bestie, take notes:

  • debug β€” a flag that turns on debugging prints ✨
  • version β€” the protocol version currently in use
  • uid β€” the name of the client, and pls note it's (unverified)
  • sid β€” the name of the server, also (unverified)
  • addr β€” the network address of the remote side

vtconn initializes a fresh new connection structure using the file descriptors infd and outfd for reading and writing β€” and yeah, they're allowed to be the same one, no drama. 🫢

vtdial dials up the network address you give it (peep dial(3)) and hands you back the corresponding connection. if the connection can't be established? it returns nil. sad but true 😭

vtversion exchanges version info with the remote side exactly like venti(7) describes. the negotiated version gets stored in z->version. slay, negotiation. πŸ’…

vtsend writes a packet (check venti-packet(3)) on the connection z. pro tip: the packet p should be a formatted Venti message, like the kind vtfcallpack would return, and vtsend will add the two-byte length field (again, see venti(7)) at the beginning. ⚠️ and heads up β€” vtsend frees p, even if there's an error. like it's gone gone. πŸ’€

vtrecv reads a packet from the connection z. it's the mirror twin of vtsend: the data read from the connection must start with a two-byte length, but the packet it returns will omit them. cute. πŸŽ€


πŸ¦‹ the whole blocking situation (important!!) πŸ¦‹

by default, vtsend and vtrecv block until the packet can actually be written to or read from the network. in a threaded program (see thread(3)), that might not be the vibe you want. 😬

so here's the move: if the caller arranges for vtsendproc and vtrecvproc to run in their own procs (usually by calling proccreate), then vtsend and vtrecv will yield the proc they're running in to other threads while they're waiting on the network. teamwork fr fr. 🌈

the void* argument you pass to vtsendproc and vtrecvproc must be the connection structure z. no substitutions, bestie. πŸ™ˆ

vtdebug prints the formatted message to standard error when z->debug is set. and when it's not set? literally a no-op. nothing happens. the void. πŸ’€

vthangup hangs up a connection β€” it closes the associated file descriptors and shuts down the send and receive procs if those were ever started. future calls to vtrecv or vtsend will return errors after this. and if you call vthangup again? no effect. it's already hung up, babe. ✨

vtfreeconn frees the connection structure, and it'll hang it up first if that's still necessary. considerate king behavior. πŸ‘‘

and ooh β€” if that global variable chattyventi is set, the library prints all Venti RPCs to standard error as they're sent or received. chatty indeed. πŸ’…

⭐ SOURCE ⭐

/src/libventi

πŸ’œ SEE ALSO πŸ’œ

venti(1), venti(3), venti-client(3), venti-packet(3), venti-server(3), venti(7)

πŸ”₯ DIAGNOSTICS πŸ”₯

  • routines that return pointers return nil on error
  • routines returning integers return 0 on success and -1 on error
  • all routines set errstr on error

like, every single one. no cap. 🫢


and that's the whole page!! this was VENTI-CONN(3) from the Library Functions Manual (section 3, obviously) β€” thanks for reading bestie, mwah πŸ’–πŸŽ€πŸ¦‹πŸŒΈβœ¨