Skip to content

net_lwip_webserver: utilize pbuf_copy_partial()#992

Merged
hathach merged 2 commits into
hathach:masterfrom
majbthrd:net_example_pbuf
Aug 17, 2021
Merged

net_lwip_webserver: utilize pbuf_copy_partial()#992
hathach merged 2 commits into
hathach:masterfrom
majbthrd:net_example_pbuf

Conversation

@majbthrd
Copy link
Copy Markdown
Collaborator

@majbthrd majbthrd commented Aug 3, 2021

The existing example code duplicates functionality that it turns out can be achieved with an existing function in lwIP (pbuf_copy_partial). Using pbuf_copy_partial() saves about 24 bytes in the net_lwip_webserver executable size and results in ever so slightly less code to maintain.

Copy link
Copy Markdown
Collaborator

@duempel duempel left a comment

Choose a reason for hiding this comment

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

Just tested your changes and it works fine as expected. Maybe the return value could be changed: return pbuf_copy_partial(p, dst, p->tot_len, 0);
What do you think about it?

pbuf_copy_partial(p, dst, p->tot_len, 0);

return len;
return p->tot_len;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since pbuf_copy_partial returns 'the number of bytes copied, or 0 on failure' it might be more logical to return this value instead of always p->tot_len.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That makes sense; I have added a commit that does just that. Thank you for the review and the suggestion!

Copy link
Copy Markdown
Owner

@hathach hathach left a comment

Choose a reason for hiding this comment

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

thank @majbthrd for the PR and @duempel for reviewing. It looks good.

@hathach hathach merged commit 7cbb11a into hathach:master Aug 17, 2021
@majbthrd majbthrd deleted the net_example_pbuf branch August 17, 2021 13:38
7FM pushed a commit to 7FM/tinyusb that referenced this pull request Aug 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants