#coap #iot

coap-handler

Interface to (and simple implementations) of CoAP handlers

10 releases

0.1.4 Sep 22, 2022
0.1.4-pre1 Sep 15, 2022
0.1.3 Feb 25, 2022
0.1.2 Nov 7, 2021
0.0.1 Oct 22, 2020

#428 in Network programming

Download history 86/week @ 2022-06-12 128/week @ 2022-06-19 127/week @ 2022-06-26 76/week @ 2022-07-03 127/week @ 2022-07-10 155/week @ 2022-07-17 179/week @ 2022-07-24 361/week @ 2022-07-31 520/week @ 2022-08-07 407/week @ 2022-08-14 410/week @ 2022-08-21 241/week @ 2022-08-28 238/week @ 2022-09-04 495/week @ 2022-09-11 446/week @ 2022-09-18 731/week @ 2022-09-25

1,933 downloads per month
Used in fewer than 6 crates

MIT/Apache

38KB
677 lines

Build Status

coap-handler

The coap-handler crate defines an interface between a CoAP server (that listens for requests on the network and parses the messages) and request handlers (that process the requests and creates responses from them).

The interface is generic over message formats by using the coap-message crate, which allows the handler to construct the response right into the send buffer prepared by the server implementation. By separating the request processing and the response phase, a server can be implemented even on network stacks that have only a single network buffer.

Convenience, example and reference implementations are available in the coap-handler-implementations crate.

Known shortcomings of the current interface are:

  • No consideration for asynchronous processing.

  • Handler mutability is a bit iffy -- there's no way yet for the server to express any promise about only running one handler at a time, thus handlers often hold shared references to a RefCell that is borrow_mut()'d (if no other code that can be concurrent with the CoAP server can have access to the T), or try_borrow_mut()'d (and errs back with a 5.03 Max-Age:0 response).

    Alternatives (where multiple handlers could be built based on a single mutable reference to their data) are being explored.

  • Multiple responses (as, for example, in observations) are not supported.

License: MIT OR Apache-2.0

Dependencies

~0.8–1.4MB
~32K SLoC