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:
- 17:69ff00ce39f4
- Parent:
- 16:6ebacf2946d8
- Child:
- 18:6199558632c0
diff -r 6ebacf2946d8 -r 69ff00ce39f4 SW_HTTPServer.cpp --- a/SW_HTTPServer.cpp Sun Sep 01 19:19:08 2013 +0000 +++ b/SW_HTTPServer.cpp Thu Sep 05 22:59:27 2013 +0000 @@ -14,16 +14,15 @@ #include "SW_HTTPServer.h" #include "Utility.h" -#define DEBUG +//#define DEBUG const char * DEFAULT_FILENAME = "index.htm"; // Header information to always send (must be \r\n terminated) -const char hdr_httpver[] = "HTTP/1.0"; // typically HTTP/1.0 or HTTP/1.1 +const char hdr_httpver[] = "HTTP/1.0"; // Wifly may not be able to support HTTP/1.1 protocol const char hdr_age[] = "Max-age: 0\r\n"; // expires right away const char hdr_server[] = "Server: Smart_Server v0.1\r\n"; // Server -const char hdr_dnt[] = "DNT: 1\r\n"; // Do Not Track -const char hdr_close[] = "Connection: close\r\n"; // tell the client to close the connection +const char hdr_close[] = "Connection: close\r\n"; // tell the client the server closes the connection immediately const char nl[] = "\r\n"; // final \r\n for the termination of the header @@ -165,7 +164,7 @@ int n; static unsigned int t_ref; // reference point for the PerformanceTimer -#ifdef DEBUG +#if 1 || defined(DEBUG) static state lastOp = Reset; if (lastOp != op) { const char *states[] = {"Idle", "Receiving", "Sending", "WaitingToClose", "Reset"}; @@ -180,12 +179,13 @@ case Idle: PerformanceTimer.reset(); + t_ref = (unsigned int)PerformanceTimer.read_us(); bPtr = headerbuffer; if (0 == server->accept(client)) { op = Receiving; - t_ref = (unsigned int)PerformanceTimer.read_us(); + t_ref = RecordPerformanceData(&perfData.ConnectionAccepted, t_ref); #ifdef DEBUG - pc->printf("Accept at %u\r\n", t_ref); + pc->printf("Accepted at %u\r\n", (unsigned int)PerformanceTimer.read_us()); #endif } break; @@ -200,7 +200,10 @@ bPtr[n] = '\0'; if (ParseHeader(headerbuffer)) { op = Sending; - t_ref = RecordPerformanceData(&perfData.Header, t_ref); + t_ref = RecordPerformanceData(&perfData.HeaderParsed, t_ref); +#ifdef DEBUG + pc->printf("Header Parsed at %u\r\n", (unsigned int)PerformanceTimer.read_us()); +#endif } bPtr += n; } @@ -209,12 +212,22 @@ case Sending: SendResponse(); op = WaitingToClose; - RecordPerformanceData(&perfData.SendData, t_ref); + t_ref = RecordPerformanceData(&perfData.ResponseSent, t_ref); +#ifdef DEBUG + pc->printf("Response Sent at %u\r\n", (unsigned int)PerformanceTimer.read_us()); +#endif break; case WaitingToClose: +#ifdef DEBUG + pc->printf("Connection closed entry %u\r\n", (unsigned int)PerformanceTimer.read_us()); +#endif close_connection(); op = Idle; + RecordPerformanceData(&perfData.ConnectionClosed, t_ref); +#ifdef DEBUG + pc->printf("Connection closed exit %u\r\n", (unsigned int)PerformanceTimer.read_us()); +#endif break; } } @@ -398,7 +411,6 @@ if (optional_text) { send(optional_text); } - send(hdr_dnt); send(hdr_close); send(nl); } @@ -504,15 +516,12 @@ void HTTPServer::SendResponse() { #ifdef DEBUG - pc->printf("SendResponse(%s) [%d]\r\n", queryType, __LINE__); + pc->printf("SendResponse(%s) at %u\r\n", queryType, (unsigned int)PerformanceTimer.read_us()); #endif if (strcmp(queryType, "GET") == 0 || strcmp(queryType, "POST") == 0) { if (!(queryString[0] == '.' && queryString[1] == '.')) { const char * fType; -#ifdef DEBUG - pc->printf(" SendResponse() [%d]\r\n", __LINE__); -#endif if (!CheckDynamicHandlers()) { // Otherwise, this queryString must be trying to reference a static file if (queryString[strlen(queryString)-1] == '/') { @@ -536,6 +545,10 @@ //pc->printf("Unsupported query type %s\r\n", queryType); header(400, "Bad Request", "Pragma: err - Unsupported query type\r\n"); } +#ifdef DEBUG + pc->printf(" SendResponse complete at %u\r\n", (unsigned int)PerformanceTimer.read_us()); +#endif + if (queryType) { myfree(queryType); queryType = NULL; @@ -548,6 +561,9 @@ myfree(postQueryString); postQueryString = NULL; } +#ifdef DEBUG + pc->printf(" SendResponse free at %u\r\n", (unsigned int)PerformanceTimer.read_us()); +#endif } @@ -720,6 +736,10 @@ memcpy(p, &perfData, sizeof(perfData)); } +unsigned int HTTPServer::GetPerformanceClock() +{ + return (unsigned int)PerformanceTimer.read_us(); +} unsigned int HTTPServer::RecordPerformanceData(SW_PerformanceParam * param, unsigned int refTime) {