[riot-notifications] [RIOT-OS/RIOT] net/nanocoap: Packet API return error if buffer full (#10931)

Ken Bannister notifications at github.com
Sun Feb 3 13:32:50 CET 2019

### Contribution description
nanocoap's Packet API is meant to be safer to use than the Buffer API. Historically, an attempt to overfill the buffer with this API would generate an assert. However, given the pressure to optimize buffer sizes, it can be useful to provide the ability to recover from a write that would overfill the buffer.

This PR builds on #10823 to return -ENOSPC if a request to write to the message buffer is too long. This response applies to coap_opt_add_xxx() and coap_opt_finish() functions. An error return value allows an application response to recover, for example by returning a 5.00 error.

This PR also updates the module documentation to be clearer about application responsibility for managing the message buffer with each API.

### Testing procedure
Includes unit tests for nanocoap and gcoap.

### Issues/PRs references
Completes the work started in #10823 and #10926.
You can view, comment on, or merge this pull request online at:


-- Commit Summary --

  * net/nanocoap: add inline function for Content-Format
  * net/gcoap: use coap_opt_finish within gcoap
  * net/gcoap: use coap_opt_finish in unit tests
  * net/gcoap: update module doc for coap_opt_finish
  * examples/gcoap: use coap_opt_finish()
  * examples/cord_epsim: use coap_opt_finish()
  * examples/cord_ep: use coap_opt_finish()
  * net/nanocoap: Return error from coap_opt_add_xxx() if no space
  * net/nanocoap: return error from coap_opt_finish if no space
  * net/nanocoap: clarify API buffer space doc
  * tests/nanocoap: verify error when overfill buffer
  * net/gcoap: verify error when overfill on coap_opt_finish

-- File Changes --

    M examples/cord_ep/main.c (8)
    M examples/cord_epsim/main.c (4)
    M examples/gcoap/gcoap_cli.c (40)
    M sys/include/net/gcoap.h (85)
    M sys/include/net/nanocoap.h (39)
    M sys/net/application_layer/cord/ep/cord_ep.c (4)
    M sys/net/application_layer/cord/epsim/cord_epsim.c (2)
    M sys/net/application_layer/gcoap/gcoap.c (35)
    M sys/net/application_layer/nanocoap/nanocoap.c (21)
    M tests/unittests/tests-gcoap/tests-gcoap.c (46)
    M tests/unittests/tests-nanocoap/tests-nanocoap.c (12)

-- Patch Links --


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190203/6cb5c576/attachment.html>

More information about the notifications mailing list