Skip to content
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

Merged

Conversation

miri64
Copy link
Member

@miri64 miri64 commented Jun 8, 2018

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

@miri64 miri64 added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR Area: CoAP Area: Constrained Application Protocol implementations labels Jun 8, 2018
@miri64 miri64 requested a review from kb2ma June 8, 2018 06:01
Copy link
Member

@kb2ma kb2ma left a 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. */
Copy link
Member

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)) {
Copy link
Member

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?

Copy link
Member Author

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 ^^"

@miri64
Copy link
Member Author

miri64 commented Jun 11, 2018

Addressed change request.

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.

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)?

@kb2ma
Copy link
Member

kb2ma commented Jun 11, 2018

Mh, but this option must be implemented first, right (+ its presence checked [in the code for this PR] )

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.

Copy link
Member

@kb2ma kb2ma left a 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;
Copy link
Member

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. ;-)

Copy link
Member Author

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)) {
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@kb2ma
Copy link
Member

kb2ma commented Jun 15, 2018

Looks good and tests OK on native! Please squash.

@miri64 miri64 force-pushed the gcoap/enh/clients-without-response-handlers branch from b35a939 to b03aa52 Compare June 15, 2018 07:46
@miri64
Copy link
Member Author

miri64 commented Jun 15, 2018

Squashed

kb2ma
kb2ma previously approved these changes Jun 15, 2018
@kb2ma kb2ma added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jun 15, 2018
@kb2ma kb2ma dismissed their stale review June 15, 2018 10:24

Commit line length too long.

@kb2ma
Copy link
Member

kb2ma commented Jun 15, 2018

Apologies @miri64, I just noticed the commit message length. Would you please cut it back to 50 chars.

@miri64
Copy link
Member Author

miri64 commented Jun 15, 2018

Why? <72 chars is perfectly fine as well. That's why it is just a warning but not an error.

@miri64
Copy link
Member Author

miri64 commented Jun 15, 2018

I honestly don't think I can make it any shorter and still be meaningful

@kb2ma
Copy link
Member

kb2ma commented Jun 15, 2018

@miri64, maybe I'm just confused on this point. The PR guidelines page says:

Be aware that each commit title is only allowed to have 50 characters.

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 dist/tools/commit-msg/check.sh only errors when any line greater than 72 chars. OTOH, I recall being asked to cut back the first line myself on another PR.

I'm just trying to be a good (but not pedantic) maintainer here. :-) If the CI build is happy, I should be happy, too?

@miri64
Copy link
Member Author

miri64 commented Jun 15, 2018

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 dist/tools/commit-msg/check.sh only errors when any line greater than 72 chars. OTOH, I recall being asked to cut back the first line myself on another PR.

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.

@miri64
Copy link
Member Author

miri64 commented Jun 15, 2018

Fixed the guidelines ;-)

Copy link
Member

@kb2ma kb2ma left a 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!

@kb2ma
Copy link
Member

kb2ma commented Jun 15, 2018

We have a consensus of happiness, so let's go!

@kb2ma kb2ma merged commit 4f8c3b7 into RIOT-OS:master Jun 15, 2018
@miri64 miri64 deleted the gcoap/enh/clients-without-response-handlers branch June 15, 2018 14:29
@miri64
Copy link
Member Author

miri64 commented Jun 15, 2018

Thanks! :-)

@cladmi cladmi added this to the Release 2018.07 milestone Jul 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: CoAP Area: Constrained Application Protocol implementations CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants