Add InTransaction(), fix param storage

This commit is contained in:
flamingcow
2019-05-09 23:36:31 -07:00
parent 8bd0813161
commit b5b0cbd599
2 changed files with 13 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
#pragma once
#include <functional>
#include <mutex>
#include <unordered_map>
@@ -22,7 +23,7 @@ class Request {
void AddParam(const std::string_view& key, const std::string_view& value);
void SetBody(const std::string_view& in);
const std::string_view& GetParam(const std::string& key);
const std::string_view& GetParam(const std::string_view& key);
const std::string_view& GetBody();
void WriteHeader(const std::string_view& name, const std::string_view& value);
@@ -33,6 +34,9 @@ class Request {
template<typename...Args>
void WriteBody(const std::string_view& first, Args... more);
template<typename T>
T InTransaction(const std::function<T()>& callback);
private:
Header OutputHeader();
iovec OutputVec();
@@ -55,4 +59,10 @@ void Request::WriteBody(const std::string_view& first, Args... more) {
WriteBody(more...);
}
template<typename T>
T Request::InTransaction(const std::function<T()>& callback) {
std::lock_guard<std::recursive_mutex> l(output_mu_);
return callback();
}
} // namespace firecgi