[nanomsg] Re: nn_recv with padding

  • From: Martin Sustrik <sustrik@xxxxxxxxxx>
  • To: nanomsg@xxxxxxxxxxxxx
  • Date: Mon, 12 May 2014 14:19:55 +0200

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 12/05/14 13:36, Drew Crawford wrote:
> I still don’t think I’ve managed to state my problem intelligibly, 
> terribly sorry.
> 
> I’m not going to send the data onwards again.  The data’s final 
> destination is the current program.  When I have received it from
> the socket, that’s the end as far as nanomsg is concerned.  There
> is no send call.
> 
> Rather, I’m going to pass the data array to some C function.  The
> C function’s API requires that bytes [16-N] contain the data, and
> C function will write output to bytes [0-15].  Maybe that’s a dumb
> API—I didn’t write it—but anyway there is a clear performance and 
> compatibility rationale for the API to work that way.
> 
> So the question is how to produce a contiguous array such that the
> first 16 bytes are valid (but maybe not initialized) and the rest
> of the array contains the message, without calling memcpy.

Ok, got you. You want nanomsg to allocate a buffer slightly bigger
than the message.

Unfortunately, this is not possible (unless you give up on zero-copy).

Take for example IPC transport. Sender allocates 1000 bytes in shared
memory and sends it to the receiver. However, receiver wants to
receive 1016 bytes. What now?

Same with inproc. Sender allocates a 1000 byte message and sends it to
the receiver. In reality, only a pointer to the buffer is passed. Now,
the receiver wants slightly larger buffer... Shrug.

Martin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJTcLxrAAoJENTpVjxCNN9Y5ysIAJaMVaLmORwxdpuq7I1ojbOV
6cwXIG+1yci8KYPqrNTjhqBR8fMLDHZIa8OqAwjaEPnWTscrAuASIHi/l1v6Qr2j
j8VD/chX4xbIrzjpjqfDvp9GmdWRzKQaXjKLSZP8EhOXbDfbtI/kWEjEM4nlSPni
RcE+OPfZs0elj8aBTILsW+unhQr1MGEsIQY6GBAqEJk0lllM1WzM1VqEjzkPRpil
1IVr9Dz+QyCAnFhqj54F/CClfTeYE780Zn3DkTaEtsKfMdFvmbAshxcADzFlFnfI
/6td2rU91rx3HfSesUHYMaQcBKWMOVFQBdK+BF5Nw/xaB+uh/IGdo1t/LE7HqJs=
=YzJw
-----END PGP SIGNATURE-----

Other related posts: