SOCKET_FASTOPEN_CONNECT6(3)

πŸ“¦
version 0.34 Β· 2 versions
  • 0.34 Β· alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.30 Β· fedora 43, fedora 44, ubuntu jammy
, in alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ socket_fastopen_connect6 β€” the NAME bit ✨

okay so bestie, this is socket_fastopen_connect6, and it lives in the Library Functions Manual (section 3, obviously πŸ’…). Its whole entire job? make a TCP connection and send some data. That's it. That's the girl. πŸŽ€


🌸 SYNTAX 🌸

first you gotta pull in the header, no cap:

#include <libowfat/socket.h>

and here's the function signature, character for character, don't @ me:

ssize_t socket_fastopen_connect6(int s,
                 const char ip[16],uint16 port,uint32 scope_id,
                 const char* buf,size_t len);

πŸ’– DESCRIPTION πŸ’–

so socket_fastopen_connect6 tries to make a connection from TCP socket s to TCP port port on IP address ip. and if that pops off? then it tries to send len bytes from buf. simple. iconic. πŸ¦‹

now here's the tea β˜• β€” the difference between this and just calling socket_connect6 and then write is that on platforms that support TCP Fast Open, socket_fastopen_connect6 will send that first data packet in the third packet of the TCP handshake, which saves one whole useless ACK packet in network traffic. we love efficiency, we love not wasting packets, periodt. πŸ”₯

heads up though: this is only useful for protocols where the client sends the first bytes. if your protocol doesn't do that, this ain't it, bestie πŸ™ˆ

and the manpage literally says socket_connect6 may return β€” yes it says socket_connect6, not this one, iykyk, i don't make the rules 😭 β€” so here's what that return situation looks like:

  • >=0 β€” the connection succeeded and this many bytes were sent ✨
  • -1 β€” and it sets errno to error_inprogress or error_wouldblock, which means the socket is non-blocking
  • -1 β€” and it sets errno to something else, which means the connection failed (and it failed immediately, if the socket is non-blocking)

when a background connection succeeds or fails, s becomes writable β€” you can use socket_connected to see whether the connection actually succeeded. and if the connection failed, socket_connected returns 0 and sets errno appropriately. keeping receipts, always 🫢

once a TCP socket is connected, you can use the read and write system calls to transmit data. the classics, still slaying πŸ‘‘

alsoooo you can call socket_connect6 without calling socket_bind6 first β€” it has the same effect as calling socket_bind6 with IP address :: and port 0. no prep needed, main character energy πŸ’…


🧚 EXAMPLE 🧚

here's the whole vibe, verbatim:

#include <libowfat/socket.h>

int s;
char ip[16];
uint16 p;
uint32 scope_id;

s = socket_tcp6b();
socket_bind6(s,ip,p);
socket_fastopen_connect6(s,ip,p,scope_id,"hello",5);

look at her go πŸ˜­πŸ’–


⭐ SEE ALSO ⭐

go read these next, they're all in the friend group:


okay that's the whole page, no notes πŸ’œ huge shoutout to the Library Functions Manual for hosting this banger, and to socket_fastopen_connect6(3) herself β€” the page title, the footer, the moment, the icon πŸ‘‘ bye bestie, go send some bytes πŸ¦‹βœ¨