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

Move HTTP strings into flash and provide suitable functions #1459

Merged
merged 3 commits into from
Oct 5, 2018

Conversation

mikee47
Copy link
Contributor

@mikee47 mikee47 commented Oct 5, 2018

http-parser - patch update

  • place tokens[] into flash memory and use get_token() function instead - doesn't rely on mforce32 compiler support to save RAM
  • Remove http_errno_name() - replaced with httpGetErrnoName() defined in HttpCommon.cpp. Note the replacement returns a String, not a const char*

HttpCommon

  • Add httpGetErrnoName(), httpGetErrnoDescription() and httpGetStatusText() functions - saves RAM by storing text strings in flash

HttpServerConnection

  • getStatus() method removed, superseded by httpGetStatusText() function. The message parameter is now a const String&, instead of const char*. As the default value is nullptr, if () statement works as expected.

FlashString.h

  • Add FSTR_TABLE macro

Samples/Basic_Progmem

  • Add demo code for use of FSTR_TABLE

http-parser - patch update
* place tokens[] into flash memory and use get_token() function instead - doesn't rely on mforce32 compiler support to save RAM
* Remove http_errno_name() - replaced with httpGetErrnoName() defined in HttpCommon.cpp. Note the replacement returns a String, not a const char*

HttpCommon
* Add httpGetErrnoName(), httpGetErrnoDescription() and httpGetStatusText() functions - saves RAM by storing text strings in flash

HttpServerConnection
* getStatus() method removed, superseded by httpGetStatusText() function. The _message_ parameter is now a const String&, instead of const char*. As the default value is nullptr, if () statement works as expected.

FlashString.h
* Add FSTR_TABLE macro

Samples/Basic_Progmem
* Add demo code for use of FSTR_TABLE
@mikee47
Copy link
Contributor Author

mikee47 commented Oct 5, 2018

Saves > 4K of RAM. Test code:

#include "Network/Http/HttpCommon.h"

void testHttpCommon()
{
	for (int i = 0; i < 100; ++i) {
		auto err = static_cast<http_errno>(i);
		debug_i("httpError(%d) = \"%s\", \"%s\"", i, httpGetErrnoName(err).c_str(),
			httpGetErrnoDescription(err).c_str());
	}

	for (int i = 100; i < 550; ++i) {
		debug_i("http_status(%d) = \"%s\"", i, httpGetStatusText(i).c_str());
	}

}

Copy link
Contributor

@slaff slaff left a comment

Choose a reason for hiding this comment

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

Looks good but small changes are needed.

samples/Basic_ProgMem/app/TestProgmem.cpp Show resolved Hide resolved
Sming/SmingCore/Network/Http/HttpCommon.cpp Outdated Show resolved Hide resolved
Sming/SmingCore/Network/Http/HttpCommon.cpp Outdated Show resolved Hide resolved
@slaff slaff added this to the 3.6.2 milestone Oct 5, 2018
@slaff slaff removed the 3 - Review label Oct 5, 2018
@slaff slaff merged commit 6253999 into SmingHub:develop Oct 5, 2018
@mikee47 mikee47 deleted the feature/http-strings branch October 5, 2018 13:57
@mikee47
Copy link
Contributor Author

mikee47 commented Oct 8, 2018

Closes #1173

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.

2 participants