mirror of
https://github.com/me-no-dev/ESPAsyncWebServer.git
synced 2025-09-28 07:11:01 +02:00
Wrap cbuf inside AsyncResponseStream with a std::unique_ptr
Fraction of commit 8bb1c704cd70dd58b318b296154a5404a1bd27d0 of dumbfixes branch of 0xFEEDC0DE64 fork of ESPAsyncWebServer. Split off for clarity.
This commit is contained in:
@@ -27,6 +27,8 @@
|
|||||||
#undef max
|
#undef max
|
||||||
#endif
|
#endif
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
// It is possible to restore these defines, but one can use _min and _max instead. Or std::min, std::max.
|
// It is possible to restore these defines, but one can use _min and _max instead. Or std::min, std::max.
|
||||||
|
|
||||||
class AsyncBasicResponse: public AsyncWebServerResponse {
|
class AsyncBasicResponse: public AsyncWebServerResponse {
|
||||||
@@ -122,7 +124,7 @@ class cbuf;
|
|||||||
|
|
||||||
class AsyncResponseStream: public AsyncAbstractResponse, public Print {
|
class AsyncResponseStream: public AsyncAbstractResponse, public Print {
|
||||||
private:
|
private:
|
||||||
cbuf *_content;
|
std::unique_ptr<cbuf> _content;
|
||||||
public:
|
public:
|
||||||
AsyncResponseStream(const String& contentType, size_t bufferSize);
|
AsyncResponseStream(const String& contentType, size_t bufferSize);
|
||||||
~AsyncResponseStream();
|
~AsyncResponseStream();
|
||||||
|
@@ -675,16 +675,15 @@ size_t AsyncProgmemResponse::_fillBuffer(uint8_t *data, size_t len){
|
|||||||
* Response Stream (You can print/write/printf to it, up to the contentLen bytes)
|
* Response Stream (You can print/write/printf to it, up to the contentLen bytes)
|
||||||
* */
|
* */
|
||||||
|
|
||||||
AsyncResponseStream::AsyncResponseStream(const String& contentType, size_t bufferSize){
|
AsyncResponseStream::AsyncResponseStream(const String& contentType, size_t bufferSize)
|
||||||
|
{
|
||||||
_code = 200;
|
_code = 200;
|
||||||
_contentLength = 0;
|
_contentLength = 0;
|
||||||
_contentType = contentType;
|
_contentType = contentType;
|
||||||
_content = new cbuf(bufferSize);
|
_content = std::unique_ptr<cbuf>(new cbuf(bufferSize)); //std::make_unique<cbuf>(bufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncResponseStream::~AsyncResponseStream(){
|
AsyncResponseStream::~AsyncResponseStream() = default;
|
||||||
delete _content;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t AsyncResponseStream::_fillBuffer(uint8_t *buf, size_t maxLen){
|
size_t AsyncResponseStream::_fillBuffer(uint8_t *buf, size_t maxLen){
|
||||||
return _content->read((char*)buf, maxLen);
|
return _content->read((char*)buf, maxLen);
|
||||||
|
Reference in New Issue
Block a user