URL corruption fix in WiServer: WiServer.cpp

Discussions related to the WiServer add-on code for WiShield. WiServer is a friendly, easy-to-use front end for webserver and webclient usages.

Moderator: shard7

URL corruption fix in WiServer: WiServer.cpp

Postby jrwifi » Mon Oct 25, 2010 7:03 pm

I made these changes against the latest code from the user_contrib branch against Greg Eisti's latest fixes. It fixes reconnect and corruption problems for me.
I am new to git so here is the whole file. The #define for the get_string_global max can be upped from 64 to 128 or whatever works for you. Also the #define may belong in a better place than where I put it.
Joel
jrwifi
 
Posts: 4
Joined: Sun Apr 25, 2010 8:09 pm

Re: URL corruption fix in WiServer: WiServer.cpp

Postby jrwifi » Thu Oct 28, 2010 9:20 pm

Code cleanup and off-by-one errors. I don't have commit access to github so I am putting it up here. This fixed all of my connection dropping/timeout and url corruption issues.
Attachments
WiServer.cpp.zip
(6.03 KiB) Downloaded 8 times
jrwifi
 
Posts: 4
Joined: Sun Apr 25, 2010 8:09 pm

Re: URL corruption fix in WiServer: WiServer.cpp

Postby aerodyno » Fri Nov 05, 2010 8:04 am

Cannot wait to try out these fixes. Thanks for posting! Does your code also fix the Large Packet Forces Board Reset Issue?
-savraj
aerodyno
 
Posts: 65
Joined: Tue Aug 04, 2009 8:42 pm

Re: URL corruption fix in WiServer: WiServer.cpp

Postby GregEigsti » Sun Nov 07, 2010 9:24 am

Comments - looks pretty good! Just a couple comments ;)

Code: Select all
memset(get_string_global, '\0', GET_STRING_CHARS_MAX); // Clear out any old get strings laying around
memcpy(uip_conn->appstate.request, start, len);
// You must guarantee the NULL termination again...
get_string_global[len < GET_STRING_CHARS_MAX? len: GET_STRING_CHARS_MAX-1] = '\0';


  • The memset in the code above is redundant since you are setting get_string_global[len] (or get_string_global[GET_STRING_CHARS_MAX-1]) to null and terminating the char array. In fact both the memset and setting the null on the last line may be redundant since data has already been incremented before any pointer arithmetic is done - but I'd leave the last line in (setting terminating char/null) for safety reasons.
  • GET_STRING_CHARS_MAX should be renamed and moved to a more accessible place (e.g. moved to somewhere like app-conf.h in the user contrib stuff and renamed to something more descriptive such as WISERVER_GET_STRING_CHARS_MAX).
  • Finally, do we even need a separate buffer to hold this data (get_string_global)? From a quick look at WiServer.cpp it looks like we could do everything in place in uip_appdata and reduce the memory impact of the extra buffer.

Thanks and sorry it has taken so long to get back on this; work has been busy to say the least.
Greg
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website

Re: URL corruption fix in WiServer: WiServer.cpp

Postby GregEigsti » Sun Nov 07, 2010 11:14 am

This change, or the essence of, has been pushed to the user contrib branch with the following comment:
jrwifi changes to make WiServer more stable. Removes malloc() and replaces with global char buffer to hold URL/GET data to be passed to WiServer/SimpleServer app's page generation callback function.


It builds and the basic SimpleServer sketch still works for me :)

I considered removing the extra buffer (get_string_global) completely but doing so would break the philosophy of WiServer - simplicity for the end user.

Give it a whirl and let me know if things are not working for you. Also, the #define that sets the length of the new buffer has been moved into app-conf.h so that the user does not have to go multiple places to change stack values for their app.

Thanks!
Greg
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website

Re: URL corruption fix in WiServer: WiServer.cpp

Postby jrwifi » Mon Nov 15, 2010 8:38 am

Greg et al,
I have tested with 50,000 requests from a test script and all looks well. I did a temporary fork of _user_contrib to also play with
moving "security_passphrase" to a normal char. I run the WiFi shields on various projects and I am storing the configs for WiFi in EEPROM
so I don't have to keep changing the hardcoded wifi credentials every time I upgrade. I'll let you know how it goes. Thanks again for cleaning up the code.
Joel
jrwifi
 
Posts: 4
Joined: Sun Apr 25, 2010 8:09 pm


Return to WiServer

Who is online

Users browsing this forum: No registered users and 1 guest