GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  NN_RECV (3)

.ds Aq ’

NAME

nn_recv - receive a message

CONTENTS

SYNOPSIS

#include <nanomsg/nn.h>

int nn_recv (int s, void *buf, size_t len, int flags);

DESCRIPTION

Receive a message from the socket s and store it in the buffer referenced by the buf argument. Any bytes exceeding the length specified by the len argument will be truncated.

Alternatively, nanomsg can allocate the buffer for you. To do so, let the buf parameter be a pointer to a void* variable (pointer to pointer) to the receive buffer and set the len parameter to NN_MSG. If the call is successful the user is responsible for deallocating the message using the nn_freemsg(3) function.

The flags argument is a combination of the flags defined below:

NN_DONTWAIT

Specifies that the operation should be performed in non-blocking mode. If the message cannot be received straight away, the function will fail with errno set to EAGAIN.

RETURN VALUE

If the function succeeds number of bytes in the message is returned. Otherwise, -1 is returned and errno is set to to one of the values defined below.

ERRORS

EBADF

The provided socket is invalid.

ENOTSUP

The operation is not supported by this socket type.

EFSM

The operation cannot be performed on this socket at the moment because socket is not in the appropriate state. This error may occur with socket types that switch between several states.

EAGAIN

Non-blocking mode was requested and there\(cqs no message to receive at the moment.

EINTR

The operation was interrupted by delivery of a signal before the message was received.

ETIMEDOUT

Individual socket types may define their own specific timeouts. If such timeout is hit this error will be returned.

ETERM

The library is terminating.

EXAMPLES

Receiving a message into a buffer allocated by the user

This example code will retrieve a message of either 100 bytes or less. If a larger message was sent it will be truncated to 100 bytes.

char buf [100];
nbytes = nn_recv (s, buf, sizeof (buf), 0);

Receiving a message into a buffer allocated by nanomsg

The following will get a message from the pipe with a buffer allocated by the system. It is large enough to accommodate the entire message. This is a good way to get the entire message without truncating if the size of the message is unknown. It is the user\(cqs responsibility to call nn_freemsg(3) after processing the message.

void *buf = NULL;
nbytes = nn_recv (s, &buf, NN_MSG, 0);

if (nbytes < 0) { /* handle error */ ... } else { /* process message */ ... nn_freemsg (buf); }

Note that this can be more efficient than manually allocating a buffer since it is a zero-copy operation.

SEE ALSO

nn_send(3) nn_recvmsg(3) nn_socket(3) nanomsg(7)

AUTHORS

Martin Sustrik <\m[blue]sustrik@250bpm.com\m[][1]>

NOTES

1. sustrik@250bpm.com  mailto:sustrik@250bpm.com
Search for    or go to Top of page |  Section 3 |  Main Index


nanomsg Unknown NN_RECV (3) 03/17/2016

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.