HTTP Server upon new mbed Ethernet Interface. Based on original code by Henry Leinen.
Dependencies: EthernetInterface mbed-rtos mbed
Fork of HTTP_server by
Diff: HTTPServer.h
- Revision:
- 2:dc9184e97328
- Parent:
- 0:fcceff3299be
- Child:
- 3:27b3a889b327
--- a/HTTPServer.h Fri Jul 26 22:33:47 2013 +0000 +++ b/HTTPServer.h Sun Jul 28 07:53:35 2013 +0000 @@ -31,6 +31,18 @@ #include <string> #include <map> +#define BUFFER_SIZE 256 +#define TIMEOUT 800 +#define OK 0 +#define ERROR -1 +#define EMPTY -2 +#define MIN_LONG 3 +#define MAX_CHUNK_SIZE 512 +#define MIN_CHUNK_SIZE 128 + +#define DEBUG 0 +#include "debug.h" + enum RequestType { HTTP_RT_GET, /*!< GET request */ HTTP_RT_POST, /*!< POST request */ @@ -55,8 +67,6 @@ RequestType request_type; }; -#define BUFFER_SIZE 256 - class HTTPServer { private: @@ -73,10 +83,32 @@ void handleRequest (); int handleGetRequest(); int handlePostRequest(); - void startResponse (int returnCode, long nLen); - void processResponse (int nLen, char* body); + void startResponse (int returnCode, int nLen); void handleError (int errorCode); + int tcpsend (const char* text, int param) { + //if (cliente == NULL) {return ERROR;} + sprintf (buffer, text, param); + int len = strlen (buffer); + if (cliente->send_all (buffer, len) == len) { + return OK; + } else { + WARN("Unsent bytes left !"); + return ERROR; + } + } + + int tcpsend (const char* text) { + //if (cliente == NULL) {return ERROR;} + int len = strlen (text); + if (cliente->send_all ((char*)text, len) == len) { + return OK; + } else { + WARN("Unsent bytes left !"); + return ERROR; + } + } + public: /** Constructor for HTTPServer objects. */ HTTPServer (int port, const char* _path);