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

nn_recv(3compat)

NAME

nn_recv - receive data (compatible API)

SYNOPSIS

#include <nanomsg/nn.h>

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

DESCRIPTION

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.

RETURN VALUES

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

ERRORS

EAGAIN

The operation would block.

EBADF

The socket sock is not open.

EFSM

The socket cannot receive in this state.

ENOTSUP

This protocol cannot receive.

ETIMEDOUT

Operation timed out.

SEE ALSO