SOCKET_ACCEPT4_SETCLOSEONEXEC(3)

✨ socket_accept4_setcloseonexec β€” the "accept it AND make it close-on-exec" glow-up ✨

okay bestie, settle in, we're in the Library Functions Manual and this one is a lil function from libowfat that does exactly what its very long name says πŸ’…


🌸 NAME 🌸

socket_accept4_setcloseonexec β€” accept an IPv4 TCP connection on a socket and set it to close on exec


πŸ¦‹ SYNTAX πŸ¦‹

#include <libowfat/socket.h>

int socket_accept4_setcloseonexec(int s,char ip[4],uint16 *port);

πŸ’– DESCRIPTION πŸ’–

so here's the tea, bestie: this is functionally equivalent to calling socket_accept4 and then calling io_closeonexec on the socket that comes back. literally the same outcome, no cap.

but however β€” and this is the iconic part β€” it may save you a syscall or two, and in the process it avoids a race condition. like, she's doing the same thing but she's doing it smarter. main character energy fr fr πŸ”₯


πŸŽ€ EXAMPLE πŸŽ€

#include <libowfat/socket.h>

int s;
char ip[4];
uint16 p;

s = socket_tcp4();
socket_bind4(s,ip,p);
socket_listen(s,16);
socket_accept4_setcloseonexec(s,ip,&p);

look at her go 😭 setting up a socket, binding, listening, then accepting and setting close-on-exec in one lil move. obsessed.


πŸ‘‘ SEE ALSO πŸ‘‘


🫢 and that's the whole page, bestie! this was the Library Functions Manual entry for socket_acc...closeonexec(3) β€” that's the name you'll see in the header and down at the bottom in the footer, iykyk. go forth and accept your connections responsibly πŸ’œ