From cd00813c0740930d389f935f0c2d7d8a11eef02d Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 13 May 2022 22:33:12 +0200 Subject: refactor(minion): wifi module create http request object in stack --- minion/src/http/request.cpp | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'minion/src/http/request.cpp') diff --git a/minion/src/http/request.cpp b/minion/src/http/request.cpp index 9a35d37..9baf7cc 100644 --- a/minion/src/http/request.cpp +++ b/minion/src/http/request.cpp @@ -55,7 +55,7 @@ auto str_to_http_request_method(const char *http_request_method_str) -> HTTPRequ } HTTPRequest::HTTPRequest( - size_t connection_id, + int connection_id, HTTPRequestMethod method, char *http_version, // NOLINT(bugprone-easily-swappable-parameters) char *path, @@ -71,12 +71,23 @@ HTTPRequest::HTTPRequest( { } +HTTPRequest::HTTPRequest(HTTPRequest &&other) noexcept + : _connection_id(other._connection_id), + _method(other._method), + _http_version(other._http_version), + _path(other._path), + _data_length(other._data_length), + _data(other._data) +{ + other._data = nullptr; +} + HTTPRequest::~HTTPRequest() noexcept { free(_data); } -auto HTTPRequest::connection_id() const noexcept -> size_t +auto HTTPRequest::connection_id() const noexcept -> int { return _connection_id; } @@ -105,3 +116,30 @@ auto HTTPRequest::data() const noexcept -> const char * { return _data; } + +auto HTTPRequest::operator=(HTTPRequest &&other) noexcept -> HTTPRequest & +{ + if (this != &other) + { + free(_data); + _data = other._data; + other._data = nullptr; + } + + return *this; +} + +HTTPRequest HTTPRequest::create_invalid() noexcept +{ + return HTTPRequest(); +} + +HTTPRequest::HTTPRequest() noexcept + : _connection_id(-1), + _method(HTTPRequestMethod(-1)), + _http_version(""), + _path(""), + _data_length(0), + _data(nullptr) +{ +} -- cgit v1.2.3-18-g5258