NN_BIND(3)
π NN_BIND(3) π
okay bestie, buckle up, we're doing nanomsg 1.2.2 today and this one is genuinely a bop. it's nn_bind, it lives in section 3 (the library girlies), and it's about to make your socket β¨socialβ¨.
πΈ NAME πΈ
nn_bind β add a local endpoint to the socket π«Ά
like. that's it. that's the whole job. you're giving your socket an address so other apps can come find it. it's giving "posting your location in the group chat" energy.
β¨ SYNOPSIS β¨
#include <nanomsg/nn.h>
int nn_bind (int s, const char *addr);
two args, one int back. no cap, it's that simple.
π DESCRIPTION π
So. nn_bind adds a local endpoint to the socket s. Once it's bound, other applications can connect to it. you're basically putting your socket on the map, fr fr.
The addr argument is made of two parts, and the format is:
transport://address
- the
transportpart = which underlying transport protocol you're using π₯ - the
addresspart = whatever that specific transport protocol decides it means (it's protocol-specific, iykyk)
For the full list of available transport protocols, go check the list on the nanomsg(7) manual page. it's all there, bestie.
The maximum length of the addr parameter is specified by NN_SOCKADDR_MAX, which is defined in the <nanomsg/nn.h> header file. don't go over it, she will not tolerate it.
Also!! important!! nn_bind and nn_connect(3) may be called multiple times on the same socket, which is the whole reason a socket can talk to multiple heterogeneous endpoints at once. it's polyamorous, it's iconic, it's by design. π
π¦ NOTE π¦
listen up, this part matters. Unlike with traditional BSD sockets, this function operates asynchronously, and it returns to the caller before the operation is complete. π
so yeah β as a result, attempts to send data or receive data on the socket may not succeed until the underlying transport actually establishes a connection. it's not broken, it's just still loading. vibe check accordingly. π
π RETURN VALUE π
If the function succeeds, a positive endpoint ID is returned. β¨
That endpoint ID can later be used to remove the endpoint from the socket via the nn_shutdown(3) function. keep it somewhere safe, bestie, it's your receipt.
If the function fails, then -1 is returned and errno is set to one of the values defined below. π
π ERRORS π
EBADFβ the provided socket is invalid. girl, that socket is not real.EMFILEβ maximum number of active endpoints was reached. you've hit the ceiling, no more plus-ones.EINVALβ the syntax of the supplied address is invalid. typo era, unfortunately.ENAMETOOLONGβ the supplied address is too long. she's doing too much.EPROTONOSUPPORTβ the requested transport protocol is not supported. that transport said "not my department".EADDRNOTAVAILβ the requested endpoint is not local. it's giving "that's not yours".ENODEVβ address specifies a nonexistent interface. that interface ghosted you.EADDRINUSEβ the requested local endpoint is already in use. occupied!! somebody's already there!!ETERMβ the library is terminating. it's over, she's leaving, the library is closing. π
π EXAMPLE π
s = nn_socket (AF_SP, NN_PUB);
eid1 = nn_bind (s, "inproc://test");
eid2 = nn_bind (s, "tcp://127.0.0.1:5560");
look at her go. two binds, one socket, multiple endpoints. main character energy. π
β SEE ALSO β
nn_inproc(7) nn_ipc(7) nn_tcp(7) nn_socket(3) nn_connect(3) nn_shutdown(3) nanomsg(7)
π AUTHORS π
- Martin Sustrik
<sustrik@250bpm.com> - Garrett DβAmore
<garrett@damore.org>
and that's the whole page, bestie!! huge thanks to the nanomsg girlies β this one's from the nanomsg 1.2.2 era, dated 2026-01-16. go bind something cute. mwah. π«Άπβ¨
π¦ where this page comes from
- fedora 44: nanomsg-devel 1.2.2-2.fc44 Β· MIT
- fedora 44: nanomsg-devel 1.2.2-2.fc44 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms