KHTTP_WRITE(3)
π KHTTP_WRITE(3) β bestie edition
okay so real quick, this is a page from the Library Functions Manual (yes that's the manual name, we stan a whole collection) and it's about khttp_write from libkcgi. buckle up π
πΈ LIBRARY
library βlibkcgiβ β that's the one. the icon. the moment.
β¨ SYNOPSIS
like, here's exactly what you type, no cap:
#include <sys/types.h>
#include <stdarg.h>
#include <stdint.h>
#include <kcgi.h>
enum kcgi_err
khttp_write(struct kreq *req, const char *buf, size_t sz);
π DESCRIPTION
okay so khttp_write writes binary data. you hand it buf (that's your data) and sz (that's how long it is, in bytes), and it shoves it into a kcgi(3) context req β and that req has to be one you already allocated with khttp_parse(3) or khttp_fcgi_parse(3). iykyk.
important timing note: you should only call this after khttp_body(3). like, order matters bestie. π«Ά
and if buf is NULL or sz is zero? it just does nothing. literally nothing. no drama, no error, just vibes. π
π¨ no but seriously: ifkcgi_writer_disable(3)was invoked earlier, this function willabort(3). like, full process abort. that's not a drill, that's the actual behaviour. be careful out there.
π₯ RETURN VALUES
it returns an enum kcgi_err telling you the error state. here's the whole lineup:
KCGI_OKβ success, bestie! π not an error. we love to see it.KCGI_ENOMEMβ internal memory allocation failure. the memory said no π.KCGI_HUPβ the output connection has been terminated. for FastCGI connections specifically, you should release the current connection withkhttp_free(3)and reenter the parse loop. periodt.KCGI_FORMβ the connection is still expecting headers withkhttp_head(3). this meanskhttp_body(3)either didn't return with success or was never invoked at all π. for FastCGI connections, again: release the current connection withkhttp_free(3)and reenter the parse loop.KCGI_SYSTEMβ internal system error while writing to the output stream. rough. π
π SEE ALSO
the whole friend group, go read them too:
π AUTHORS
Written by Kristaps Dzonsons <kristaps@bsd.lv>. king behaviour honestly.
and that's the whole page! π huge shoutout to Debian for shipping it, this is from the $Mdocdate$ build, and yes it's KHTTP_WRITE(3) all the way at the bottom too β go forth and write your HTTP content data, bestie, you're gonna slay π¦β¨
π¦ where this page comes from
- alpine 3.24: kcgi-doc 1.0.1-r0 Β· ISC
- Copyright (c) 2014, 2018, 2020 Kristaps Dzonsons <kristaps@bsd.lv>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms