-
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
gcoap: don't allocate memo for clients without response handlers #9310
gcoap: don't allocate memo for clients without response handlers #9310
Conversation
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.
Sounds good to me, and simple to implement. This PR actually fits in with RFC 7967, which specifies a No-Response option to ask the server not to send a response to certain requests.
Also see l.890. Must check for NULL memo there, too. ;-)
@@ -796,71 +796,75 @@ size_t gcoap_req_send2(const uint8_t *buf, size_t len, | |||
gcoap_resp_handler_t resp_handler) | |||
{ | |||
gcoap_request_memo_t *memo = NULL; | |||
unsigned msg_type = (*buf & 0x30) >> 4; | |||
|
|||
assert(remote != NULL); | |||
|
|||
/* Find empty slot in list of open requests. */ |
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.
Move this comment inside the conditional? I found it confusing to leave here. OTOH, it might be good to add a new comment here, like "Allocate memo if necessary"
memo->msg.data.pdu_buf = &_coap_state.resend_bufs[i][0]; | ||
memcpy(memo->msg.data.pdu_buf, buf, GCOAP_PDU_BUF_SIZE); | ||
memo->msg.data.pdu_len = len; | ||
if ((resp_handler != NULL) || (msg_type == COAP_TYPE_NON)) { |
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.
Shouldn't the check here be for COAP_TYPE_CON rather than NON?
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.
Yes, you are right... This was probably a typo ^^"
Addressed change request.
Mh, but this option must be implemented first, right (+ its presence checked in https://github.com/RIOT-OS/RIOT/pull/9310/files#diff-9739e1bd2e91135c214745f71bc5c86aR805 then as well)? |
Yes, this PR is a good first step down the road. First, we reduce processing on the client device in this PR, then we ask the server device to not send the response in the first place, by implementing 7967. Changes look good. Give me a chance to run some tests. |
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.
My tests worked after fixing the two items in this review. Let's go through one more round before squashing.
} | ||
else { | ||
|
||
uint32_t timeout = 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.
Must move this initialization above the 'resp_handler != NULL' conditional. Otherwise, l.869 won't compile. ;-)
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, done (this time tested ;-))
@@ -883,7 +889,7 @@ size_t gcoap_req_send2(const uint8_t *buf, size_t len, | |||
DEBUG("gcoap: can't wake up mbox; no timeout for msg\n"); | |||
} | |||
} | |||
if (res <= 0) { | |||
if ((memo != NULL) && (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.
Please rework this conditional so the DEBUG stmt on l.897 still is executed when memo is NULL.
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.
Done
Looks good and tests OK on native! Please squash. |
b35a939
to
b03aa52
Compare
Squashed |
Apologies @miri64, I just noticed the commit message length. Would you please cut it back to 50 chars. |
Why? <72 chars is perfectly fine as well. That's why it is just a warning but not an error. |
I honestly don't think I can make it any shorter and still be meaningful |
@miri64, maybe I'm just confused on this point. The PR guidelines page says:
I thought the requirement was for the first line, i.e. the title, to be no longer than 50 characters, but subsequent lines in the commit message could be longer. I see that I'm just trying to be a good (but not pedantic) maintainer here. :-) If the CI build is happy, I should be happy, too? |
If the PR guidelines say that, they are wrong, I think. Normal git best practices (which I practice in both contribution and review) is that commit messages should be ideally <50 characters but no longer than 72 (which is also the cut GitHub makes in showing the summary line and is also the hard limit Git uses internally). So we should try to achieve <50 chars, but not enforce if, if the reasons for it are reasonable (which in my case I think they are). We have the same "stretchy" conditional for our code line length (try for <80, but have 100 at max), so I think it is reasonable to have this for commit messages as well. |
Fixed the guidelines ;-) |
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 updating the PR guidelines!
We have a consensus of happiness, so let's go! |
Thanks! :-) |
Contribution description
@haukepetersen and I were discussing this the other day offline: If the client doesn't want to handle the response we don't need to add a waiter for it (saving that space for other requests that do want to get a response + allowing for "spamming" NON requests, without much memory requirements¹). I'm not 100% sure if I did not miss anything, but this small fix should allow for that.
¹ This might be required e.g. for ergonomic applications, like a game controller, where the feedback of an action should be somewhat immediately.
Issues/PRs references
None