Single instance HTTP Server using new Ethernet Interface. Blocking mode only; this improved stability, but the HTTP server must be started from a separate thread.
Fork of HTTPServer by
Diff: HTTPConnection.cpp
- Revision:
- 13:aa5338a5e452
- Parent:
- 11:3943841e1798
- Child:
- 16:cc3f5c53d0d5
diff -r ba81cc117fb6 -r aa5338a5e452 HTTPConnection.cpp --- a/HTTPConnection.cpp Wed Jun 05 23:39:24 2013 +0000 +++ b/HTTPConnection.cpp Sat Jun 22 15:41:34 2013 +0000 @@ -2,24 +2,14 @@ #include "mbed.h" #include "HTTPConnection.h" - -#define _DEBUG 0 +#define DEBUG +#include "debug.h" #include <vector> using std::vector; using std::string; -#if (_DEBUG && !defined(TARGET_LPC11U24)) -#define INFO(x, ...) std::printf("[HttpConnection : INFO]"x"\r\n", ##__VA_ARGS__); -#define WARN(x, ...) std::printf("[HttpConnection : WARN]"x"\r\n", ##__VA_ARGS__); -#define ERR(x, ...) std::printf("[HttpConnection : ERR]"x"\r\n", ##__VA_ARGS__); -#else -#define INFO(x, ...) -#define WARN(x, ...) -#define ERR(x, ...) -#endif - const struct HTTPRequestConfig { @@ -37,7 +27,7 @@ }; -HTTPConnection::HTTPConnection() +HTTPConnection::HTTPConnection(TCPSocketConnection& clnt) : m_Tcp(clnt) { } @@ -108,8 +98,13 @@ if ((szLine == NULL) || (nMaxLen == 0)) return -1; + szLine[0] = 0; m_Tcp.set_blocking(false); + if (!m_Tcp.is_connected()) { + error("NOT COnnected anymore"); + return -1; + } Timer tm; int i; @@ -129,7 +124,9 @@ // Check if line terminating character was received if (szLine[i] == cLineTerm) + { break; + } } // Terminate with \0 szLine[i] = 0; @@ -139,7 +136,6 @@ i--; szLine[i] = 0; } - INFO("receiveLine : \"%s\".", szLine); // return number of characters received in the line or return -2 if an empty line was received if ((i == 0) || ((i==1) &&(szLine[0] == '\r')))