[nanomsg] Re: Changes to the API

  • From: Martin Sustrik <sustrik@xxxxxxxxxx>
  • To: nanomsg@xxxxxxxxxxxxx
  • Date: Wed, 23 Jan 2013 22:03:20 +0100

On 23/01/13 21:49, Martin Sustrik wrote:

Why not make NN_MSG a flag? Like the following:

void *buf = nn_allocmsg (10, 0);
memset (buf, 0xab, 10);
nn_send (s, buf, sizeof(buf), NN_MSG);

void *buf;
nn_recv (s,&buf, sizeof(buf), NN_MSG);
nn_freemsg (buf);

Btw, here's how nn_sendmsg would look like:

01 void *buf = nn_allocmsg (10, 0);
02 memset (buf, 0xab, 10);
03 struct nn_msghdr hdr;
04 struct nn_iovec iov;
05 iov.iov_base = &buf;  <---------------
06 iov.iov_len = sizeof (buf);
07 memset (&hdr, 0, sizeof (hdr));
08 hdr.msg_iov = iov;
09 hdr.msg_iovlen = 1;
10 nn_sendmsg (s, &hdr, NN_MSG); <----------

Note that specifying that buffer is set to the buf pointer at line 5. Then, at line 10 we specify that we don't want to send the pointer itself, rather the buffer it points to. Specifying these two closely related pieces of information at two distinct places looks a bit error-prone.

Martin

Other related posts: