Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SW_HTTPServer by
Diff: SW_HTTPServer.cpp
- Revision:
- 7:99ad7a67f05e
- Parent:
- 5:c9b27e718054
- Child:
- 8:262583f054f6
--- a/SW_HTTPServer.cpp Tue Jun 25 18:11:10 2013 +0000 +++ b/SW_HTTPServer.cpp Thu Jun 27 17:08:25 2013 +0000 @@ -14,7 +14,7 @@ #include "SW_HTTPServer.h" #include "Utility.h" -//#define DEBUG +#define DEBUG const char * DEFAULT_FILENAME = "index.htm"; @@ -46,13 +46,13 @@ }; HTTPServer::HTTPServer( - Wifly * _wf, - int port, - const char * _webroot, - int _maxparams, - int _maxdynamicpages, - PC * _pc, - int _allocforheader, + Wifly * _wf, + int port, + const char * _webroot, + int _maxparams, + int _maxdynamicpages, + PC * _pc, + int _allocforheader, int _allocforfile) { wifly = _wf; @@ -124,13 +124,21 @@ Idle, // waiting for a connection Receiving, // receiving data Sending, // send the response - WaitingToClose // small timeout to close + WaitingToClose, // small timeout to close + Reset } state; static state op = Idle; + static state lastOp = Reset; static char * bPtr = headerbuffer; int n; static int t_ref; // reference point for the timer + #ifdef DEBUG + if (lastOp != op) { + pc->printf("%d", op); + lastOp = op; + } + #endif switch(op) { default: // not expected to arrive here op = Idle; @@ -355,14 +363,15 @@ send(nl); } -void HTTPServer::close_connection( ) +bool HTTPServer::close_connection() { -#ifndef DEBUG - wifly->close(); -#else // DEBUG - if (!wifly->close()) - pc->printf("Couldn't close connection\r\n"); + bool res; + + res = wifly->close(); +#ifdef DEBUG + pc->printf("close connection returned %d\r\n", res); #endif + return res; } bool HTTPServer::Extract(char * haystack, char * needle, char ** string) @@ -502,7 +511,7 @@ char * dblCR; bool advanceState = false; int bytecount; - + // Bad hack to have to do this here, but it isn't being set in the // underlying layer, and this is what allows it to properly "close" // when it is done. @@ -520,7 +529,7 @@ #endif char * soRec = buffer; // start of the next record of text char * eoRec = strchr(soRec, '\n'); // search for end of a record - + bytecount = strlen(buffer); if (bytecount > maxheaderbytes) maxheaderbytes = bytecount; @@ -558,7 +567,6 @@ } advanceState = true; buffer[0] = 0; -// bPtr = buffer; // This part parses the extra data on a POST method. // Since there has to be a dynamic handler registered for this @@ -628,11 +636,13 @@ return advanceState; } -void HTTPServer::GetPerformanceData(SW_PerformanceData * p) { +void HTTPServer::GetPerformanceData(SW_PerformanceData * p) +{ memcpy(p, &perfData, sizeof(perfData)); } -int HTTPServer::RecordPerformanceData(SW_PerformanceParam * param, int refTime) { +int HTTPServer::RecordPerformanceData(SW_PerformanceParam * param, int refTime) +{ int t_now = timer.read_us(); param->TotalTime_us += (t_now - refTime); param->Samples++; @@ -641,7 +651,8 @@ return t_now; } -void HTTPServer::ResetPerformanceData() { +void HTTPServer::ResetPerformanceData() +{ memset(&perfData, 0, sizeof(perfData)); }