NN_SOCKET(3)
π NN_SOCKET(3) β the nanomsg one, from the nanomsg 1.2.2 era π
okay bestie, gather round, because this is the page where everything starts π«Ά
β¨ NAME β¨
nn_socket β create an SP socket π
πΈ SYNOPSIS πΈ
#include <nanomsg/nn.h>
int nn_socket (int domain, int protocol);
π¦ DESCRIPTION π¦
So basically, nn_socket makes you a brand new SP socket, and you get to pick its domain and its protocol. What do you get back? A file descriptor for the shiny new socket you just manifested. β¨
Here are the domains that are defined at the moment, queen:
AF_SPβ the standard, full-blown SP socket. The whole entire experience. πAF_SP_RAWβ a raw SP socket. Raw sockets omit the end-to-end functionality thatAF_SPsockets have, which is exactly why you'd reach for them: they're for implementing intermediary devices in SP topologies. π§
The protocol parameter is the thing that decides what type of socket you're getting, and likeβ¦ that in turn decides the exact semantics of the socket. Go check the manual pages for the individual SP protocols to get the list of available socket types, iykyk. π
heads up: your freshly created socket is initially not associated with any endpoints. At all. Zero. If you actually want a message flow to happen, you have to add at least one endpoint to the socket with thenn_bind(3)ornn_connect(3)function. No endpoints, no messages, periodt. π
Also, real talk: notice how the type argument that shows up in the standard socket(2) function is omitted from nn_socket? Yeah. That's because all the SP sockets are message-based, so they're all of SOCK_SEQPACKET type. It's giving consistent. π
π RETURN VALUE π
If it works? You get the file descriptor of the new socket. Slay. π
If it doesn't work? You get -1, and errno is set to one of the values defined below. π
π¨ IMPORTANT, and I mean this with my whole chest: the file descriptors returned by the nn_socket function are not standard file descriptors, and they will exhibit undefined behaviour when used with system functions. Also β and this is the chaotic part β it may happen that a system file descriptor and the file descriptor of an SP socket will incidentally collide. Like, be equal. Same number. Different souls. π
π₯ ERRORS π₯
EAFNOSUPPORTβ the address family you specified is not supported. bestie that family doesn't exist πEINVALβ unknown protocol. who is she? we don't know her. πEMFILEβ the limit on the total number of open SP sockets has been reached, or the OS limit for file descriptors has been reached. either way, too many open things, no cap. πETERMβ the library is terminating. it's over, it's done, it's the end. π₯
β EXAMPLE β
int s = nn_socket (AF_SP, NN_PUB);
assert (s >= 0);
look at her go. AF_SP plus NN_PUB, asserted non-negative, iconic behaviour only. β¨
π SEE ALSO π
nn_pubsub(7) nn_reqrep(7) nn_pipeline(7) nn_survey(7) nn_bus(7) nn_bind(3) nn_connect(3) nn_close(3) nanomsg(7)
(the whole friend group, honestly π«Ά)
π AUTHORS π
Martin Sustrik <sustrik@250bpm.com>
and that's the page!! written by the legend Martin Sustrik, dated 2026-01-16, from the nanomsg 1.2.2 era of NN_SOCKET(3) β go make some sockets, bestie, you've got this π¦πβ¨
π¦ 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