-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nanocoap_sock: split generic request function of from nanocoap_get #9086
nanocoap_sock: split generic request function of from nanocoap_get #9086
Conversation
I agree that it makes sense to separate the generic packet sending mechanism from sending/handling a simple GET. Use of the coap_pkt_t for the nanocoap_request() meshes well with #9085, which provides a mechanism for building the packet struct. That PR will further simplify the packet building code in nanocoap_get(). I expect it's also nice to save that memmove() in the response handling if you have other plans. :-) |
I want to add the local
Yeah, but I don't think I can remove it without changing the current |
Koen, I reused your nanocoap_request() function in a nanocoap-based CLI app. See my riot-nano-cli repository. Thanks for making that separation from nanocoap_get()! Please consider reworking how the request function determines the length of the outgoing PDU. Presently you are using the payload_len attribute of the struct, but it's really not the payload length. If you set the payload attribute in nanocoap_get() you can determine the length with the code below, assuming payload_len is set to the length of the actual payload.
|
sys/include/net/nanocoap_sock.h
Outdated
/** | ||
* @brief Simple synchronous CoAP request | ||
* | ||
* @param[inout] pkt Packet struct containing the request. Is reused for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC use comma: in,out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack
|
||
res = nanocoap_request(&pkt, remote, len); | ||
if (res < 0) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coding style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops :(
return res; | ||
} | ||
else { | ||
res = coap_get_code(&pkt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO better use coap_get_code_class()
and then compare res != COAP_CLASS_SUCCESS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I see its copy paste from before and my suggestion would be an API change ... mhm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe in a follow up then?
Nice!
Thanks, I wasn't sure whether I was using all the struct members correctly, thanks for clarifying. Could you please verify whether the current code is behaving correctly with respect to the struct members. @smlng Thanks for the review, I've fixed your issues except for the API change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the improvement to the packet length calculation. I tested nanocoap_request() and nanocoap_get() in my CLI app, and they work as expected.
Funny what you learn when you test things though. ;-) I posted #9191 on some pre-existing logic errors, including the item @smlng pointed out. These should not hold up this PR though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I approved too quickly though, will dismiss. Needs squash if @smlng agrees we're ready.
Forgot to change the doxygen issue, is fixed now :( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nit, please amend and squash directly
sys/include/net/nanocoap_sock.h
Outdated
/** | ||
* @brief Simple synchronous CoAP request | ||
* | ||
* @param[in,out] pkt Packet struct containing the request. Is reused for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indention slightly of
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😢
The nanocoap_get function is refactored to split of the request part into a separate function for reuse by other modules. Support for retransmissions when the received frame is malformed is dropped as it was broken anyway.
8019928
to
6bb8a5c
Compare
amended and squashed! |
@kaspar030 could you please look this over, too? Note the changed behaviour when a mal formed response is received, before this would trigger a retransmit now it returns with the appropriate error. |
@kaspar030 ping! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK.
Thanks! |
Contribution description
The nanocoap_get function is refactored to split of the request part
into a separate function for reuse by other modules. Support for
retransmissions when the received frame is malformed is dropped as it
was broken anyway.
Issues/PRs references
None