[Xorp-hackers] Using results from one XRL to respond to another

Steven Simpson ss at comp.lancs.ac.uk
Wed Apr 13 06:41:37 PDT 2011


Ben,

Thanks for applying my patches, and fixing subject lines!  Here's a very
small change for your consideration...

I was just trying to apply the async facility to ECODE, and found myself
writing this function:

void
XrlEuaTciNode::direct_dispatch_cb(const XrlError& e,
				  const vector<uint8_t>* ret,
				  EuaTci01DirectDispatchCB cb)
{
  cb->dispatch(e, *ret);
}

This is meant to conform to a callback type defined by clnt-gen on one
of our interfaces, but it also takes a callback type defined by tgt-gen
on the same interface, and relays its arguments through.

[ret] is a binary out-parameter, and clnt-gen expresses it as a [const
TYPE*] in the callback type.  AFAICT, the function could be called with
ret==NULL, if e!=OKAY.

OTOH, I made tgt-gen express cb->dispatch's corresponding parameter as
[const TYPE&], so the function above has to dereference ret to match types.

I imagine that [*(const TYPE *)NULL] assigned to [const TYPE&] is
practically safe, but I suspect it's undefined behaviour, so I'd have to
write:

  cb->dispatch(e, ret ? *ret : vector<uint8_t>());

...which is not convenient, and probably a waste of time and space. 
IOW, if you are passing a non-OKAY error code, you shouldn't have to
create a load of dummy objects just to meet the signature.

I'll send another patch shortly, just a few lines in tgt-gen, to make
the callback type use pointers instead of references, so it will be
consistent with clnt-gen.  I hope that sounds reasonable.

Cheers,

Steven

-- 




More information about the Xorp-hackers mailing list