本文整理汇总了C++中msgpack::rpc::request类的典型用法代码示例。如果您正苦于以下问题:C++ request类的具体用法?C++ request怎么用?C++ request使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pop_queue_nowait
void QContentHubServer::pop_queue_nowait(msgpack::rpc::request &req, const std::string &name)
{
std::string ret;
queue_map_t &qmap = q_map.unsafe_ref();
queue_map_it_t it = qmap.find(name);
if (it == qmap.end()) {
req.result(QCONTENTHUB_STRERROR);
} else {
queue_t *q = it->second;
if (q->stop) {
req.result(QCONTENTHUB_STRAGAIN);
return;
}
pthread_mutex_lock(&(q->lock));
if (q->str_q.size() == 0) {
ret = QCONTENTHUB_STRAGAIN;
} else {
ret = q->str_q.front();
q->str_q.pop();
pthread_cond_signal(&q->not_full);
}
pthread_mutex_unlock(&(q->lock));
req.result(ret);
}
}
示例2: dispatch
void WorkerServer::dispatch(msgpack::rpc::request req)
{
try
{
std::string method;
req.method().convert(&method);
WorkerHandlerBase* handler = router_.find(method);
if (handler)
{
//handler->invoke(req);
worker_pool_.schedule_task(boost::bind(handler_wrapper, handler, req));
}
else
{
std::cerr << "[WorkerServer] Method not found: " << method << std::endl;
req.error(msgpack::rpc::NO_METHOD_ERROR);
}
}
catch (const msgpack::type_error& e)
{
std::cerr << "[WorkerServer] " << e.what() << std::endl;
req.error(msgpack::rpc::ARGUMENT_ERROR);
}
catch (const std::exception& e)
{
std::cerr << "[WorkerServer] " << e.what() << std::endl;
req.error(std::string(e.what()));
}
}
示例3: push_queue_nowait
void QContentHubServer::push_queue_nowait(msgpack::rpc::request &req, const std::string &name, const std::string &obj)
{
queue_map_t &qmap = q_map.unsafe_ref();
queue_map_it_t it = qmap.find(name);
if (it == qmap.end()) {
int ret = add_queue(name, DEFAULT_QUEUE_CAPACITY);
if (ret == QCONTENTHUB_ERROR) {
req.result(ret);
} else {
push_queue(req, name, obj);
}
} else {
queue_t *q = it->second;
pthread_mutex_lock(&q->lock);
if ((int)q->str_q.size() > q->capacity) {
pthread_mutex_unlock(&q->lock);
req.result(QCONTENTHUB_AGAIN);
} else {
q->str_q.push(obj);
pthread_cond_signal(&q->not_empty);
pthread_mutex_unlock(&q->lock);
req.result(QCONTENTHUB_OK);
}
}
}
示例4: stat_queue
void QContentHubServer::stat_queue(msgpack::rpc::request &req, const std::string &name)
{
char buf[64];
std::string ret;
int current = get_current_time();
ret.append("STAT uptime ");
sprintf(buf, "%d", current - m_start_time);
ret.append(buf);
ret.append("\n");
ret.append("STAT time ");
sprintf(buf, "%d", current);
ret.append(buf);
ret.append("\n");
queue_map_t &qmap = q_map.unsafe_ref();
queue_map_it_t it = qmap.find(name);
if (it == qmap.end()) {
req.result(ret);
} else {
ret.append("STAT name ");
ret.append(name);
ret.append("\n");
ret.append("STAT size ");
sprintf(buf, "%ld", it->second->str_q.size());
ret.append(buf);
ret.append("\n");
req.result(ret);
}
}
示例5: start_dump_all
void QUrlQueueServer::start_dump_all(msgpack::rpc::request &req)
{
if (m_dump_all_dumping) {
req.result(QCONTENTHUB_ERROR);
} else {
m_dump_all_dumping = true;
m_dump_all_it = m_site_map.unsafe_ref().begin();
req.result(QCONTENTHUB_OK);
}
}
示例6: set_queue_capacity
void QContentHubServer::set_queue_capacity(msgpack::rpc::request &req, const std::string &name, int capacity)
{
queue_map_t &qmap = q_map.unsafe_ref();
queue_map_it_t it = qmap.find(name);
if (it == qmap.end()) {
req.result(QCONTENTHUB_WARN);
} else {
queue_t *q = it->second;
pthread_mutex_lock(&q->lock);
q->capacity = capacity;
pthread_mutex_unlock(&q->lock);
}
req.result(QCONTENTHUB_OK);
}
示例7: stats
void QContentHubServer::stats(msgpack::rpc::request &req)
{
char buf[64];
std::string ret;
int current = get_current_time();
ret.append("STAT uptime ");
sprintf(buf, "%d", current - m_start_time);
ret.append(buf);
ret.append("\n");
ret.append("STAT time ");
sprintf(buf, "%d", current);
ret.append(buf);
ret.append("\n");
queue_map_t &qmap = q_map.unsafe_ref();
for (queue_map_it_t it = qmap.begin(); it != qmap.end(); it++) {
ret.append("STAT name ");
ret.append(it->first);
ret.append("\n");
ret.append("STAT size ");
sprintf(buf, "%ld", it->second->str_q.size());
ret.append(buf);
ret.append("\n");
}
req.result(ret);
}
示例8: dump_all
void QUrlQueueServer::dump_all(msgpack::rpc::request &req)
{
std::string content;
if (!m_dump_all_dumping) {
content = QCONTENTHUB_STRERROR;
} else {
mp::sync<SiteMap>::ref ref(m_site_map);
while (m_dump_all_it != ref->end()) {
Site *s = m_dump_all_it->second;
while (!s->url_queue.empty()) {
content = s->url_queue.top().value;
s->url_queue.pop();
return;
}
m_dump_all_it++;
}
if (m_dump_all_it == ref->end()) {
content = QCONTENTHUB_STREND;
m_dump_all_dumping = false;
}
}
req.result(content);
}
示例9: stats
void QUrlQueueServer::stats(msgpack::rpc::request &req)
{
char buf[64];
std::string ret;
uint64_t current_time = get_current_time();
uint64_t current = current_time / 1000;
ret.append("STAT uptime ");
sprintf(buf, "%ld", current - m_start_time);
ret.append(buf);
ret.append("\nSTAT time ");
sprintf(buf, "%ld", current);
ret.append(buf);
ret.append("\nSTAT default_interval ");
sprintf(buf, "%d", m_default_interval);
ret.append(buf);
ret.append("\nSTAT stop_all ");
sprintf(buf, "%d", m_stop_all);
ret.append(buf);
ret.append("\nSTAT site_items ");
sprintf(buf, "%ld", m_site_map.unsafe_ref().size());
ret.append(buf);
int ordered_site_size = 0;
for (int i = 0; i < MAX_PRIORITY; i++) {
sprintf(buf, "\nSTAT ordered_site_%d items ", i);
ret.append(buf);
sprintf(buf, "%ld", site_queues[i].size());
ret.append(buf);
ordered_site_size += site_queues[i].size();
}
ret.append("\nSTAT ordered_site_total items ");
sprintf(buf, "%d", ordered_site_size);
ret.append(buf);
ret.append("\nSTAT enqueue_items ");
sprintf(buf, "%ld", m_enqueue_items);
ret.append(buf);
ret.append("\nSTAT dequeue_items ");
sprintf(buf, "%ld", m_dequeue_items);
ret.append(buf);
ret.append("\nSTAT clear_items ");
sprintf(buf, "%ld", m_clear_items);
ret.append(buf);
// TODO:
// STAT curr_connections 141
ret.append("\nEND\r\n");
req.result(ret);
}
示例10: handler_wrapper
void handler_wrapper(WorkerHandlerBase* handler, msgpack::rpc::request& req)
{
try
{
handler->invoke(req);
}
catch (const msgpack::type_error& e)
{
std::cerr << "[WorkerServer] " << e.what() << std::endl;
req.error(msgpack::rpc::ARGUMENT_ERROR);
}
catch (const std::exception& e)
{
std::cerr << "[WorkerServer] " << e.what() << std::endl;
req.error(std::string(e.what()));
}
}
示例11: set_site_interval
void QUrlQueueServer::set_site_interval(msgpack::rpc::request &req, const std::string &site, int interval)
{
{
mp::sync<SiteMap>::ref ref(m_site_map);
m_site_interval_map[site] = interval;
}
req.result(QCONTENTHUB_OK);
}
示例12: set_default_interval
void QUrlQueueServer::set_default_interval(msgpack::rpc::request &req, int interval)
{
{
mp::sync<SiteMap>::ref ref(m_site_map);
m_default_interval = interval;
}
req.result(QCONTENTHUB_OK);
}
示例13: stop_site
void QUrlQueueServer::stop_site(msgpack::rpc::request &req, const std::string &site)
{
{
mp::sync<SiteMap>::ref ref(m_site_map);
SiteMapIter it = ref->find(site);
if (it != ref->end()) {
it->second->stop = true;
}
}
req.result(QCONTENTHUB_OK);
}
示例14: dispatch
void server::dispatch(msgpack::rpc::request req)
try {
std::string method;
req.method().convert(&method);
const table_type* table((table_type*)TABLE);
table_type::const_iterator m = table->find(method);
if(m == table->end()) {
req.error(msgpack::rpc::NO_METHOD_ERROR);
return;
}
(*m->second)(this, &req);
} catch (msgpack::type_error& e) {
req.error(msgpack::rpc::ARGUMENT_ERROR);
return;
} catch (std::exception& e) {
req.error(std::string(e.what()));
return;
}
示例15: push_queue
void QContentHubServer::push_queue(msgpack::rpc::request &req, const std::string &name, const std::string &obj)
{
queue_map_t &qmap = q_map.unsafe_ref();
queue_map_it_t it = qmap.find(name);
if (it == qmap.end()) {
int ret = add_queue(name, DEFAULT_QUEUE_CAPACITY);
if (ret == QCONTENTHUB_ERROR) {
req.result(ret);
} else {
push_queue(req, name, obj);
}
} else {
queue_t *q = it->second;
pthread_mutex_lock(&q->lock);
while ((int)q->str_q.size() > q->capacity) {
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
ts.tv_sec += 60;
int rc = pthread_cond_timedwait(&q->not_full, &q->lock, &ts);
if (rc == ETIMEDOUT) {
pthread_mutex_unlock(&q->lock);
req.result(QCONTENTHUB_STRAGAIN);
return;
} else if (rc != 0) {
pthread_mutex_unlock(&q->lock);
req.result(QCONTENTHUB_STRERROR);
return;
}
}
q->str_q.push(obj);
pthread_cond_signal(&q->not_empty);
pthread_mutex_unlock(&q->lock);
req.result(QCONTENTHUB_OK);
}
}