HTTP Server, WebSocket support
Fork of HTTPD by
Diff: HTTPD_util.cpp
- Revision:
- 1:b724fdb741e7
- Parent:
- 0:d18dff347122
--- a/HTTPD_util.cpp Wed Nov 13 01:58:04 2013 +0000 +++ b/HTTPD_util.cpp Thu Jun 15 20:17:24 2017 +0000 @@ -62,22 +62,46 @@ char buf[HTTPD_CMD_SIZE]; strcpy(buf, "HTTP/1.1 200 OK\r\n"); - _state[id].client->send_all(buf, strlen(buf)); + _state[id].client->send(buf, strlen(buf)); strcpy(buf, "Server: GSwifi httpd\r\n"); - _state[id].client->send_all(buf, strlen(buf)); + _state[id].client->send(buf, strlen(buf)); if (_state[id].keepalive) { strcpy(buf, "Connection: Keep-Alive\r\n"); } else { strcpy(buf, "Connection: close\r\n"); } - _state[id].client->send_all(buf, strlen(buf)); + _state[id].client->send(buf, strlen(buf)); if (header) { - _state[id].client->send_all((char*)header, strlen(header)); + _state[id].client->send((char*)header, strlen(header)); } sprintf(buf, "Content-Length: %d\r\n\r\n", len); - _state[id].client->send_all(buf, strlen(buf)); + _state[id].client->send(buf, strlen(buf)); + + return _state[id].client->send((char*)body, len); +} + +int HTTPD::sendstr (int id, const char *buf) { + return _state[id].client->send((char*)buf, strlen(buf)); +} + - return _state[id].client->send_all((char*)body, len); +int HTTPD::hprintf(int id, const char* format, ...) { + //FIX ME: This could result in memory overruns if the buffer size is exceeded + static Mutex _mtx; + static char _buf[1024]; + + std::va_list arg; + + _mtx.lock(); + + va_start(arg, format); + vsprintf(_buf, format, arg); + va_end(arg); + + int r = _state[id].client->send(_buf, strlen(_buf)); + + _mtx.unlock(); + return r; } int HTTPD::getHandler (const char *uri) {