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.
Dependencies: HTTPClient SmartRest
Diff: HTTPBuffer.cpp
- Revision:
- 2:1038411466a6
- Child:
- 3:ce2f116369bd
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPBuffer.cpp Fri Jan 24 11:39:32 2014 +0000
@@ -0,0 +1,77 @@
+#include "HTTPBuffer.h"
+#include <stdlib.h>
+
+HTTPBuffer::HTTPBuffer()
+{
+ _rptr = _wptr = _buf = NULL;
+ bufferSize(HTTPBUFFER_INITIAL_SIZE);
+}
+
+HTTPBuffer::~HTTPBuffer()
+{
+ if (_buf != NULL)
+ free(_buf);
+}
+
+char HTTPBuffer::read()
+{
+ if (_rptr == _wptr)
+ return 0;
+ return *_rptr++;
+}
+
+uint8_t HTTPBuffer::status()
+{
+ if (_rptr == _wptr)
+ return DS_STATUS_CLOSED;
+ return DS_STATUS_OK;
+}
+
+void HTTPBuffer::writeReset()
+{
+ _rptr = _wptr = _buf;
+ bufferSize(HTTPBUFFER_INITIAL_SIZE);
+}
+
+int HTTPBuffer::write(const char* buf, size_t len)
+{
+ if (_wptr - _buf + len > _len) {
+ size_t newLen = _len;
+ while (_wptr - _buf + len > newLen)
+ newLen += HTTPBUFFER_INCREMENT;
+ bufferSize(newLen);
+ }
+ memcpy(_wbuf, buf, len);
+ _wbuf += len;
+}
+
+void HTTPBuffer::setDataType(const char* type)
+{
+}
+
+void HTTPBuffer::setIsChunked(bool chunked)
+{
+}
+
+void HTTPBuffer::setDataLen(size_t len)
+{
+ bufferSize(len);
+}
+
+
+void HTTPBuffer::bufferSize(size_t length)
+{
+ if (_len == length)
+ return;
+
+ char *buf = (char*)realloc(_buf, length);
+ if (buf == NULL)
+ return;
+
+ // set pointers
+ _wptr = buf + (_wptr - _buf);
+ _rptr = buf + (_rptr - _buf);
+ _buf = buf;
+
+ _len = len;
+}