Make the response size sent through coap.sendResponse function dyanmic.#47
Make the response size sent through coap.sendResponse function dyanmic.#47trishantpahwa wants to merge 1 commit intohirotakaster:masterfrom
Conversation
|
Thanks for your contribution.
|
|
If you check the file changes, it only refers to The default size of buffer that is used to send as a response is 128 bytes, but the function |
|
Yes, I understand the increasing the response buffer via setResponseBufferSize() (e.g., to support larger responses when needed). However, once the buffer is increased, it also becomes easy to generate multi‑KB CoAP responses as a single UDP datagram, which may exceed the path MTU and rely on IP fragmentation—this can be unreliable depending on the network. If large payload support is a real requirement, RFC 7959 (Block‑Wise, e.g. Block2) is typically needed, and that also requires CoAP server/client implementation support have to need. |
|
Got it. How about setting a warning if the response size exceeds the maximum limit? Currently, it fails silently. |
|
I think it would be better to fail explicitly (e.g., return an error) when the response exceeds the configured maximum. |
|
|
Sure. I am unable to resolve the conflicts. Can you do the same please. Thanks. |
|
@trishantpahwa |
|
Hi Please merge the pull request after verifying the proper functionality of the response being sent, as I have resolved the conflicts. |
This pull request introduces support for a separate, dynamically-sized response buffer in the CoAP implementation, allowing for more flexible handling of large response payloads. The changes include modifications to both the core CoAP library and an example usage to demonstrate dynamic buffer sizing.
Response Buffer Management
resp_bufferand associatedresp_buf_sizemember to theCoapclass, allowing response packets to use a separate buffer from the transmit buffer. The constructor now accepts an optional response buffer size parameter, and memory management for the new buffer is handled in the destructor. (coap-simple.cpp,coap-simple.h)setResponseBufferSize(int size)method to allow dynamic resizing of the response buffer at runtime. (coap-simple.cpp,coap-simple.h)Packet Sending Logic
sendPacketmethods to accept a buffer and buffer size, ensuring both requests and responses can use different buffers and sizes. All internal buffer size checks now use the provided buffer size instead of a fixed value. (coap-simple.cpp,coap-simple.h)sendResponseto use the new response buffer and size. (coap-simple.cpp)Example Usage
examples/esp8266/esp8266.ino)coap-simple.cpp,examples/esp8266/esp8266.ino)