NN_DEVICE(3)

πŸ“¦
version 1.2.2 Β· 5 versions
, in fedora 44

πŸ’– 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 make nn_device actually exit?? you call nn_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 an AF_SP_RAW socket, 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 two SINK sockets 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