NN_DEVICE(3)
π NN_DEVICE(3) β bestie edition π
okay so this is nn_device, it lives in section 3 of the nanomsg 1.2.2 manual (the library function section, iykyk), and it's literally the "start a device" girlie. yes that's the whole name. we stan a concise queen. π
β¨ NAME β¨
nn_device β start a device π
πΈ SYNOPSIS πΈ
#include <nanomsg/nn.h>
int nn_device (int s1, int s2);
π DESCRIPTION π
So what this does: it starts a device that forwards messages between two sockets. That's the whole job. Glorified mail carrier. Respect. π¬
If both sockets are valid, nn_device just loops forever and sends any messages it receives from s1 to s2, and vice versa. Back and forth. Relentless. Main character energy that never clocks out. π
If only one socket is valid and the other one is negative, nn_device switches into what it calls "loopback" mode β it loops and sends any messages it received from the socket right back to itself. It's giving "talking to your own reflection." πͺβ¨
and to break the loop and makenn_deviceactually exit?? you callnn_term(3). that's the only way out, bestie. it will NOT leave on its own. π«Ά
π₯ RETURN VALUE π₯
The function loops until it hits an error. When that happens it returns -1 and sets errno to one of the values below. no in-between. it's either vibing in the loop forever or it's done. π
β ERRORS β
EBADFβ one of the sockets you handed over is invalid. not it. πEINVALβ messy, honestly. this one fires if either one of the sockets is not anAF_SP_RAWsocket, or the two sockets don't belong to the same protocol, or the directionality of the sockets doesn't fit (like, say, trying to join twoSINKsockets together to form a device β the math isn't mathing, the directions don't work). πEINTRβ the operation got interrupted by delivery of a signal. rude but legal. βETERMβ the library is terminating. it's over, we're packing up. π
π EXAMPLE π
int s1 = nn_socket (AF_SP_RAW, NN_REQ);
nn_bind (s1, "tcp://127.0.0.1:5555");
int s2 = nn_socket (AF_SP_RAW, NN_REP);
nn_bind (s2, "tcp://127.0.0.1:5556");
nn_device (s1, s2);
look at her go. NN_REQ on 5555, NN_REP on 5556, both AF_SP_RAW, and then nn_device just. does the thing. forever. π¦
π SEE ALSO π
nn_socket(3) Β· nn_term(3) Β· nanomsg(7)
π AUTHORS π
Martin Sustrik <sustrik@250bpm.com> β thank you for your service, king π
and that's the page, bestie!! this one came out 2026-01-16 with the nanomsg 1.2.2 source/version tag on it, so if you're citing it or whatever, that's the receipt. π§β¨ periodt. π
π¦ 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