mirror of
https://github.com/CrowCpp/Crow.git
synced 2024-06-07 21:10:44 +00:00
fix compile error
- add consturctor to request - remove unused type using - include "logging.h" from dumb_timer_queue.h (who uses CROW_LOG_DEBUG)
This commit is contained in:
parent
764999e6c8
commit
b1b87a6c5a
@ -1941,94 +1941,6 @@ namespace crow
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
namespace crow
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
// fast timer queue for fixed tick value.
|
||||
class dumb_timer_queue
|
||||
{
|
||||
public:
|
||||
// tls based queue to avoid locking
|
||||
static dumb_timer_queue& get_current_dumb_timer_queue()
|
||||
{
|
||||
thread_local dumb_timer_queue q;
|
||||
return q;
|
||||
}
|
||||
|
||||
using key = std::pair<dumb_timer_queue*, int>;
|
||||
|
||||
void cancel(key& k)
|
||||
{
|
||||
auto self = k.first;
|
||||
k.first = nullptr;
|
||||
if (!self)
|
||||
return;
|
||||
|
||||
unsigned int index = (unsigned int)(k.second - self->step_);
|
||||
if (index < self->dq_.size())
|
||||
self->dq_[index].second = nullptr;
|
||||
}
|
||||
|
||||
key add(std::function<void()> f)
|
||||
{
|
||||
dq_.emplace_back(std::chrono::steady_clock::now(), std::move(f));
|
||||
int ret = step_+dq_.size()-1;
|
||||
|
||||
CROW_LOG_DEBUG << "timer add inside: " << this << ' ' << ret ;
|
||||
return {this, ret};
|
||||
}
|
||||
|
||||
void process()
|
||||
{
|
||||
if (!io_service_)
|
||||
return;
|
||||
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
while(!dq_.empty())
|
||||
{
|
||||
auto& x = dq_.front();
|
||||
if (now - x.first < std::chrono::seconds(tick))
|
||||
break;
|
||||
if (x.second)
|
||||
{
|
||||
CROW_LOG_DEBUG << "timer call: " << this << ' ' << step_;
|
||||
// we know that timer handlers are very simple currenty; call here
|
||||
x.second();
|
||||
}
|
||||
dq_.pop_front();
|
||||
step_++;
|
||||
}
|
||||
}
|
||||
|
||||
void set_io_service(boost::asio::io_service& io_service)
|
||||
{
|
||||
io_service_ = &io_service;
|
||||
}
|
||||
|
||||
private:
|
||||
dumb_timer_queue() noexcept
|
||||
{
|
||||
}
|
||||
|
||||
int tick{5};
|
||||
boost::asio::io_service* io_service_{};
|
||||
std::deque<std::pair<decltype(std::chrono::steady_clock::now()), std::function<void()>>> dq_;
|
||||
int step_{};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* merged revision: 5b951d74bd66ec9d38448e0a85b1cf8b85d97db3 */
|
||||
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
||||
*
|
||||
@ -4803,8 +4715,10 @@ namespace crow
|
||||
WARNING = 2
|
||||
ERROR = 3
|
||||
CRITICAL = 4
|
||||
|
||||
default to INFO
|
||||
*/
|
||||
#define CROW_LOG_LEVEL 0
|
||||
#define CROW_LOG_LEVEL 1
|
||||
|
||||
|
||||
|
||||
@ -4939,6 +4853,97 @@ namespace crow
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
|
||||
|
||||
|
||||
namespace crow
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
// fast timer queue for fixed tick value.
|
||||
class dumb_timer_queue
|
||||
{
|
||||
public:
|
||||
// tls based queue to avoid locking
|
||||
static dumb_timer_queue& get_current_dumb_timer_queue()
|
||||
{
|
||||
thread_local dumb_timer_queue q;
|
||||
return q;
|
||||
}
|
||||
|
||||
using key = std::pair<dumb_timer_queue*, int>;
|
||||
|
||||
void cancel(key& k)
|
||||
{
|
||||
auto self = k.first;
|
||||
k.first = nullptr;
|
||||
if (!self)
|
||||
return;
|
||||
|
||||
unsigned int index = (unsigned int)(k.second - self->step_);
|
||||
if (index < self->dq_.size())
|
||||
self->dq_[index].second = nullptr;
|
||||
}
|
||||
|
||||
key add(std::function<void()> f)
|
||||
{
|
||||
dq_.emplace_back(std::chrono::steady_clock::now(), std::move(f));
|
||||
int ret = step_+dq_.size()-1;
|
||||
|
||||
CROW_LOG_DEBUG << "timer add inside: " << this << ' ' << ret ;
|
||||
return {this, ret};
|
||||
}
|
||||
|
||||
void process()
|
||||
{
|
||||
if (!io_service_)
|
||||
return;
|
||||
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
while(!dq_.empty())
|
||||
{
|
||||
auto& x = dq_.front();
|
||||
if (now - x.first < std::chrono::seconds(tick))
|
||||
break;
|
||||
if (x.second)
|
||||
{
|
||||
CROW_LOG_DEBUG << "timer call: " << this << ' ' << step_;
|
||||
// we know that timer handlers are very simple currenty; call here
|
||||
x.second();
|
||||
}
|
||||
dq_.pop_front();
|
||||
step_++;
|
||||
}
|
||||
}
|
||||
|
||||
void set_io_service(boost::asio::io_service& io_service)
|
||||
{
|
||||
io_service_ = &io_service;
|
||||
}
|
||||
|
||||
private:
|
||||
dumb_timer_queue() noexcept
|
||||
{
|
||||
}
|
||||
|
||||
int tick{5};
|
||||
boost::asio::io_service* io_service_{};
|
||||
std::deque<std::pair<decltype(std::chrono::steady_clock::now()), std::function<void()>>> dq_;
|
||||
int step_{};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include "logging.h"
|
||||
|
||||
namespace crow
|
||||
{
|
||||
namespace detail
|
||||
|
@ -52,7 +52,6 @@ namespace crow
|
||||
bool middleware_call_helper(Container& middlewares, request& req, response& res, Context& ctx)
|
||||
{
|
||||
using parent_context_t = typename Context::template partial<N-1>;
|
||||
using current_context_t = typename Context::template partial<N>;
|
||||
before_handler_call<CurrentMW, Context, parent_context_t>(std::get<N>(middlewares), req, res, ctx, static_cast<parent_context_t&>(ctx));
|
||||
|
||||
if (res.is_completed())
|
||||
@ -86,7 +85,6 @@ namespace crow
|
||||
typename std::enable_if<(N==0)>::type after_handlers_call_helper(Container& middlewares, Context& ctx, request& req, response& res)
|
||||
{
|
||||
using parent_context_t = typename Context::template partial<N-1>;
|
||||
using current_context_t = typename Context::template partial<N>;
|
||||
using CurrentMW = typename std::tuple_element<N, typename std::remove_reference<Container>::type>::type;
|
||||
after_handler_call<CurrentMW, Context, parent_context_t>(std::get<N>(middlewares), req, res, ctx, static_cast<parent_context_t&>(ctx));
|
||||
}
|
||||
@ -95,7 +93,6 @@ namespace crow
|
||||
typename std::enable_if<(N>0)>::type after_handlers_call_helper(Container& middlewares, Context& ctx, request& req, response& res)
|
||||
{
|
||||
using parent_context_t = typename Context::template partial<N-1>;
|
||||
using current_context_t = typename Context::template partial<N>;
|
||||
using CurrentMW = typename std::tuple_element<N, typename std::remove_reference<Container>::type>::type;
|
||||
after_handler_call<CurrentMW, Context, parent_context_t>(std::get<N>(middlewares), req, res, ctx, static_cast<parent_context_t&>(ctx));
|
||||
after_handlers_call_helper<N-1, Context, Container>(middlewares, ctx, req, res);
|
||||
|
@ -23,6 +23,18 @@ namespace crow
|
||||
ci_map headers;
|
||||
std::string body;
|
||||
|
||||
void* middleware_context{};
|
||||
|
||||
request()
|
||||
: method(HTTPMethod::GET)
|
||||
{
|
||||
}
|
||||
|
||||
request(HTTPMethod method, std::string url, ci_map headers, std::string body)
|
||||
: method(method), url(std::move(url)), headers(std::move(headers)), body(std::move(body))
|
||||
{
|
||||
}
|
||||
|
||||
void add_header(std::string key, std::string value)
|
||||
{
|
||||
headers.emplace(std::move(key), std::move(value));
|
||||
@ -33,6 +45,5 @@ namespace crow
|
||||
return crow::get_header_value(headers, key);
|
||||
}
|
||||
|
||||
void* middleware_context{};
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user