[nanomsg] nn_req extension

  • From: Drew Crawford <drew@xxxxxxxxxxxxxxxxxx>
  • To: nanomsg@xxxxxxxxxxxxx
  • Date: Thu, 5 Jun 2014 04:02:46 -0500

I’m trying to lay a protocol on top on nn_req similar to how nn_req is layered 
on nn_xreq

nn_req extends nn_xreq by patching the xreq’s vfptr to contain a mix of req and 
xreq functions.  This is possible for a variety of reasons:

nn_xreq_init, which consumes the vfptr, is declared in a header file
struct nn_xreq, which is also required for nn_xreq_init, is also declared in a 
header file
Various xreq functions are also in the header file, which is convenient, but 
not strictly speaking, required—req could get many of these out of the vfptr 
itself rather than specify them by name

Meanwhile with nn_req the analogous conditions are all false, which make it 
hard to patch req’s vfptr:

nn_req_init is private
struct nn_req, which would be required to use it, is considered private
All the nn_req_* family is private

This makes it somewhat difficult to extend nn_req. 

Many of these problems can be solved by judicious use of extern (which may lead 
to future breakages, but at least they’re caught at compile-time).  However the 
private struct is problematic, because in order to allocate it to pass to 
nn_req_init, the size must be known, and sizeof doesn’t play well with structs 
that are defined in another compilation unit.  Analogous problems exist in the 
other protocols.

IMO req/rep structs etc. should move to an internal header file as xreq/xrep 
are.

Alternatively some internal API should be provided to allow patching the vfptr 
values on an arbitrary sockbase after the sockbase has already been 
initialized.  In this way req could be extended without any knowledge of the 
layout of nn_req etc.

Drew

Other related posts: