From fe5b89b1e658f133c098e8eacb9cdf2bffd51d82 Mon Sep 17 00:00:00 2001 From: buda <mbudiselicbuda@gmail.com> Date: Thu, 24 Sep 2015 23:25:40 +0200 Subject: [PATCH] stupid mistakes are changed --- speedy/speedy.hpp | 4 +++- speedy/speedy.inl | 18 +++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/speedy/speedy.hpp b/speedy/speedy.hpp index cc17b7bd5..f30e260b9 100644 --- a/speedy/speedy.hpp +++ b/speedy/speedy.hpp @@ -19,7 +19,9 @@ private: http::Ipv4 ip; node *n; std::vector<http::request_cb_t> callbacks; - void store_index(int method, const std::string &path); + void store_callback(int method, + const std::string &path, + http::request_cb_t callback); public: Speedy(uv::UvLoop& loop, const http::Ipv4& ip); void get(const std::string &path, http::request_cb_t callback); diff --git a/speedy/speedy.inl b/speedy/speedy.inl index b56d7cd60..03e354e94 100644 --- a/speedy/speedy.inl +++ b/speedy/speedy.inl @@ -25,8 +25,11 @@ Speedy::Speedy(uv::UvLoop& loop, const http::Ipv4& ip) : server(loop), ip(ip) n = r3_tree_create(100); } -void Speedy::store_index(int method, const std::string &path) +void Speedy::store_callback(int method, + const std::string &path, + http::request_cb_t callback) { + callbacks.push_back(callback); void *ptr = malloc(sizeof(uint)); *((uint *)ptr) = callbacks.size() - 1; r3_tree_insert_routel(n, method, path.c_str(), path.size(), ptr); @@ -34,30 +37,27 @@ void Speedy::store_index(int method, const std::string &path) void Speedy::get(const std::string &path, http::request_cb_t callback) { - callbacks.push_back(callback); - store_index(METHOD_GET, path); + store_callback(METHOD_GET, path, callback); // TODO: something like this // this solution doesn't work, currenlty I don't know why + // callbacks.push_back(callback) // r3_tree_insert_pathl(n, path.c_str(), path.size(), &callbacks.back()); } void Speedy::post(const std::string &path, http::request_cb_t callback) { - callbacks.push_back(callback); - store_index(METHOD_POST, path); + store_callback(METHOD_POST, path, callback); } void Speedy::put(const std::string &path, http::request_cb_t callback) { - callbacks.push_back(callback); - store_index(METHOD_PUT, path); + store_callback(METHOD_PUT, path, callback); } void Speedy::del(const std::string &path, http::request_cb_t callback) { - callbacks.push_back(callback); - store_index(METHOD_DELETE, path); + store_callback(METHOD_DELETE, path, callback); } void Speedy::listen()