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

CaptivePortalAdvanced: Fix compatibility with Android #5069

Merged
merged 6 commits into from
Feb 5, 2019

Conversation

engycz
Copy link
Contributor

@engycz engycz commented Aug 22, 2018

Android refuses to show page with missing Content-Length header.
Prepare page data to String and send it with server.send

@engycz engycz force-pushed the master branch 4 times, most recently from a68c875 to d84a8d4 Compare August 22, 2018 11:35
Android refuses to show page with missing Content-Length header.
Prepare page data to String and send it with server.send
Moved respose strings to PROGMEM
Copy link
Collaborator

@d-a-v d-a-v left a comment

Choose a reason for hiding this comment

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

Approving since it solves a compatibility issue.

As said, several other strings could be PROGMEMed, I guess a(nother) general pass over all examples may fix that.

A comment would be welcome for readers to understand that in that particular HTTP case, special care with String/PROGMEM should be considered to avoid ram waste and malloc holes.

@Misiu
Copy link

Misiu commented Jan 9, 2019

Will this get merged as part of 2.5.0?

@d-a-v d-a-v added this to the 2.5.0 milestone Jan 9, 2019
@d-a-v d-a-v requested a review from devyte January 9, 2019 16:41
Copy link
Collaborator

@devyte devyte left a comment

Choose a reason for hiding this comment

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

You're doing several String concats in a row, which leads to mem fragmentation. I suggest figuring out an approximate upper bound to the resulting String size, and using Page.reserve(blah) beforehand. Given that this is an example, I think it would help users who play with this code.

A bit of explanation at this point:
C-style strings, i.e.: "blah", that are identical are unified during the build process.into a single one that is held in RAM.
Moving multiple C-style strings to flash breaks that unification, i.e.: the build process can't unify the ones declared to be in flash. If all instances of a string are moved to flash, then the bin size increases by the string size * number of string instances, and I think plus a pointer (4 bytes) to each instance.
To avoid the problem, you have to manually unify the strings, e.g.: declare a single one globally to be in flash, then use it everywhere.

There is a certain string size threshold for deciding whether to move to flash. I think the following, but this should be verified:

  • at 4 bytes (3 chars + null term) it makes no difference (move string to flash saves 4 bytes, but creates a pointer which is also 4 bytes)
  • strings bigger than 4 bytes (or 3 chars) should be moved to flash, but it should be done unifying all instances.
  • strings smaller than 4 bytes (or 3 chars) should not be moved to flash. It doesn't help and increases bin size.

Again, the previous should not be taken at face value, and should be verified.

@d-a-v d-a-v self-assigned this Feb 4, 2019
Copy link
Collaborator

@d-a-v d-a-v left a comment

Choose a reason for hiding this comment

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

Tested, working, thanks!

@d-a-v d-a-v merged commit c218d94 into esp8266:master Feb 5, 2019
@Misiu
Copy link

Misiu commented Feb 5, 2019

@d-a-v what about @devyte comment? This is just a hint (to consider) or some additional changes are required?

@d-a-v
Copy link
Collaborator

d-a-v commented Feb 5, 2019

It is a general comment on String usage.
We will address this in all examples eventually.

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.

5 participants