This documentation is for version v1.3.0 of NNG, but the latest released version is v1.8.0. see the documentation for v1.8.0 for the most up-to-date information.


#include <nanomsg/nn.h>

int nn_recv(int sock, void *data, size_t size, int flags)


The nn_recv() function receives a message from the socket sock. The message body must fit within size bytes, and will be stored at the location specified by data, unless size is the special value NN_MSG, indicating a zero-copy operation.

This function is provided for API compatibility with legacy libnanomsg. Consider using the relevant modern API instead.

If size has the special value NN_MSG, then a zero-copy operation is performed. In this case, instead of copying the message data into the address specified by data, a new message large enough to hold the message data will be allocated (as if by the function nn_allocmsg()), and the message payload will be stored accordingly. In this case, the value stored at data will not be message data, but a pointer to the message itself. In this case, on success, the caller shall take responsibility for the final disposition of the message (such as by sending it to another peer using nn_send()) or nn_freemsg().

The flags field may contain the special flag NN_DONTWAIT. In this case, if the no message is available for immediate receipt, the operation shall not block, but instead will fail with the error EAGAIN.


This function returns the number of bytes sent on success, and -1 on error.



The operation would block.


The socket sock is not open.


The socket cannot receive in this state.


This protocol cannot receive.


Operation timed out.