EXPLAIN_SOCKETPAIR_OR_DIE(3)
π explain_socketpair_or_die(3) π
okay bestie, gather round, we're doing the libexplain thing. this is from the Library Functions Manual, and it's literally the glow-up your error handling has been begging for β¨
πΈ NAME πΈ
explain_socketpair_or_die β create pair of connected sockets and report errors
no cap, that's the whole job description π«Ά
β¨ SYNOPSIS β¨
#include <libexplain/socketpair.h>
void explain_socketpair_or_die(int domain, int type, int protocol, int *sv);
int explain_socketpair_on_error(int domain, int type, int protocol, int *sv);
two functions, one header, zero drama π
π¦ DESCRIPTION π¦
so here's the tea. the explain_socketpair_or_die function is used to call the socketpair(2) system call. and if it fails? an explanation gets printed to stderr, which it snags from the explain_socketpair(3) function, and then the process terminates by calling exit(EXIT_FAILURE). it's giving "we don't do silent failures in this house" π
meanwhile, the explain_socketpair_on_error function is also used to call the socketpair(2) system call. on failure an explanation will be printed to stderr, again obtained from the explain_socketpair(3) function β but this one still returns to the caller. so it's the chill sibling. no dramatic exit, just a little note and back to business π
π the arguments, bestie
domainβ the domain, exactly as to be passed to thesocketpair(2)system call.typeβ the type, exactly as to be passed to thesocketpair(2)system call.protocolβ the protocol, exactly as to be passed to thesocketpair(2)system call.svβ thesv, exactly as to be passed to thesocketpair(2)system call.
see the pattern? exactly as to be passed to the socketpair(2) system call. don't get creative, don't freestyle, just pass it through, periodt π
π RETURN VALUE π
the explain_socketpair_or_die function only returns on success β see socketpair(2) for more information. on failure, it prints an explanation and exits, it does not return. so like, if you ever see a line of code after it, just know that line is living on borrowed time π
the explain_socketpair_on_error function always returns the value return by the wrapped socketpair(2) system call. (yes, "return by", that's the original's wording, we're keeping it verbatim, don't @ me π)
π₯ EXAMPLE π₯
the explain_socketpair_or_die function is intended to be used in a fashion similar to the following example:
explain_socketpair_or_die(domain, type, protocol, sv);
that's it. that's the whole vibe. one line, and your errors explain themselves π«
π SEE ALSO π
socketpair(2)β create a pair of connected socketsexplain_socketpair(3)β explainsocketpair(2)errorsexit(2)β terminate the calling process
π COPYRIGHT π
this whole thing is libexplain version 1.4 and it's Copyright (C) 2010 Peter Miller. respect the icon, they wrote the library that holds your hand through every syscall failure π«Ά
okay so that's the page, bestie! go forth and let your sockets fail loudly and with receipts. π β¨
libexplain version 1.4 Β· Copyright (C) 2010 Peter Miller β mwah, thanks for reading, no cap ππ¦
π¦ where this page comes from
- debian bookworm: libexplain-dev 1.4.D001-12+b1 Β· LGPL-3.0-or-later
- debian trixie: libexplain-dev 1.4.D001-16 Β· LGPL-3.0-or-later
- ubuntu jammy: libexplain-dev 1.4.D001-12 Β· LGPL-3.0-or-later
- ubuntu noble: libexplain-dev 1.4.D001-13 Β· LGPL-3.0-or-later
- ubuntu resolute: libexplain-dev 1.4.D001-16 Β· LGPL-3.0-or-later
- Copyright (C) 2010, 2011 Peter Miller
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms