Browse files

delete request and handler

  • Loading branch information...
1 parent 8f2d543 commit 5ed5798148c83ffc572c83b8f4e2a707fa38c494 @erikfrey erikfrey committed Mar 15, 2013
Showing with 32 additions and 6 deletions.
  1. +2 −0 include/darner/net/handler.h
  2. +6 −5 include/darner/net/request.h
  3. +12 −0 include/darner/util/queue_map.hpp
  4. +7 −0 src/net/handler.cpp
  5. +5 −1 src/net/request.cpp
View
2 include/darner/net/handler.h
@@ -52,6 +52,8 @@ class handler : public boost::enable_shared_from_this<handler>
void write_version();
+ void destroy(); // really "delete", but that's a reserved word
+
void flush();
void flush_all();
View
11 include/darner/net/request.h
@@ -15,10 +15,11 @@ struct request
{
RT_STATS = 1,
RT_VERSION = 2,
- RT_FLUSH = 3,
- RT_FLUSH_ALL = 4,
- RT_SET = 5,
- RT_GET = 6
+ RT_DESTROY = 3,
+ RT_FLUSH = 4,
+ RT_FLUSH_ALL = 5,
+ RT_SET = 6,
+ RT_GET = 7
};
request_type type;
@@ -37,7 +38,7 @@ struct request_grammar : boost::spirit::qi::grammar<std::string::const_iterator>
request_grammar();
request req;
boost::spirit::qi::rule<std::string::const_iterator, std::string()> key_name;
- boost::spirit::qi::rule<std::string::const_iterator> stats, version, flush, flush_all, set_option, set, get_option, get, start;
+ boost::spirit::qi::rule<std::string::const_iterator> stats, version, destroy, flush, flush_all, set_option, set, get_option, get, start;
};
// grammar are expensive to construct. to be thread-safe, let's make one grammar per thread.
View
12 include/darner/util/queue_map.hpp
@@ -50,6 +50,18 @@ class queue_map
return it->second;
}
+ void erase(const std::string& queue_name)
+ {
+ iterator it = queues_.find(queue_name);
+
+ if (it == queues_.end())
+ return;
+
+ it->second->destroy();
+
+ queues_.erase(it);
+ }
+
iterator begin() { return queues_.begin(); }
iterator end() { return queues_.end(); }
const_iterator begin() const { return queues_.begin(); }
View
7 src/net/handler.cpp
@@ -63,6 +63,7 @@ void handler::parse_request(const system::error_code& e, size_t bytes_transferre
{
case request::RT_STATS: write_stats(); break;
case request::RT_VERSION: write_version(); break;
+ case request::RT_DESTROY: destroy(); break;
case request::RT_FLUSH: flush(); break;
case request::RT_FLUSH_ALL: flush_all(); break;
case request::RT_SET: ++stats_.cmd_sets; set(); break;
@@ -90,6 +91,12 @@ void handler::write_version()
async_write(socket_, buffer(buf_), bind(&handler::read_request, shared_from_this(), _1, _2));
}
+void handler::destroy()
+{
+ queues_.erase(req_.queue);
+ return end("DELETED");
+}
+
void handler::flush()
{
// TODO: implement
View
6 src/net/request.cpp
@@ -22,6 +22,10 @@ request_grammar::request_grammar()
version =
lit("version") [phoenix::ref(req.type) = request::RT_VERSION];
+ destroy =
+ lit("delete ") [phoenix::ref(req.type) = request::RT_DESTROY]
+ >> key_name [phoenix::ref(req.queue) = _1];
+
flush =
lit("flush ") [phoenix::ref(req.type) = request::RT_FLUSH]
>> key_name [phoenix::ref(req.queue) = _1];
@@ -61,5 +65,5 @@ request_grammar::request_grammar()
>> *get_option
>> -lit(' '); // be permissive to clients inserting spaces
- start = (stats | version | flush | flush_all | set | get) >> eol;
+ start = (stats | version | destroy | flush | flush_all | set | get) >> eol;
}

0 comments on commit 5ed5798

Please sign in to comment.