this sidesteps the copying parts of coap_parse_pdu, using the directo
allocation of the pdu payload data from the package's pbuf, whose
reference is consumed.
the old implementation stuffed the pdu struct in front of the
transport-level pbuf, and preserved it on the stack while the packages
were sent.
this had two advantages:
* saving ram
* preserving the other implementation's structure of pdu->hdr == pdu+1
(ie. starting right after the pdu struct)
but two disadvantages:
* bad readability and pointer juggling in the send routine
* relying on the send function to block until the package is out (which
works for simple implementations of lwip drivers but not dma etc)
if something really assumes the contiguous memory structure, it will
show (unfortunately by corrupting other pdu structs), and chances are
people use ->hdr anyway.
if the coap pdu struct is larger than the headers that are stripped off
a datagram by the time it arrives at coap, all the nice zero-copying
stops working. instead of working around by allocating bigger headers
(which would go untested), it was decided to lock up. given how
reproducible the header calculations are, this will let the developer
know what's up early, if this ever happens to be critical at all.
there are two plausible causes for this to happen:
* the pdu struct grows, eg. because of additional fields or becaus it is
used on architecture with large alignment requirements
* packages "come in shallow", that is, are created from an interface
that barely has headers. such an interface could be a network
interfaces created from a hardware network stack.
this also changes the sizes of allocated pdus, in which previously, the
probelm was not considered and covered by overallocation.
the coap_add_option_later works like coap_add_option, but does not take
data. instead, it allocates the option empty, and returns an address the
application has to fill with data later.
this is especially useful for the etag and block options; the
application can write out its variable data, generate a checksum while
writing, and fill the etag when the data is already written to the pdu.
with the block options, the more flag can be set at the last moment.
The subdirectory "tests" now contains a growing set of unit tests for the
libcoap API. To use this, you will need CUnit (see http://cunit.sourceforge.net)
and must configure with the option --with-tests.