enum store_item_type do_store_item(item *it, const uint32_t hv) { enum store_item_type stored; char *key = ITEM_key(it); item *old_it = do_item_get(key, it->nkey, hv); if (old_it != NULL) { assert(old_it != it); before_write(old_it); do_item_unlink_nolock(old_it, hv); //do_item_remove(old_it); /* release our reference */ item_free(old_it); assert((old_it->it_flags & ITEM_LINKED) == 0); assert((old_it->it_flags & ITEM_SLABBED) != 0); after_write(old_it); } before_write(it); int ret = do_item_link_nolock(it, hv); after_write(it); if (ret == 0) { stored = NOT_STORED; printf("not stored\n"); } else { stored = STORED; } return stored; }
void HttpConnection::write_rsp(context_ptr context) { if (izenelib::driver::asBool(context->jsonRequest_.header()["check_fibp_time"])) { context->jsonResponse_[driver::Keys::timers][driver::Keys::total_server_time] = context->serverTimer_.elapsed(); } context->rsp_.code_ = http::OK; // we only suppose the response is json if raw body is empty. // If the raw body has data, we thought the handler has everything done. if (context->rsp_.body_.empty()) { writer_->write(context->jsonResponse_.get(), context->rsp_.body_); } context->rsp_.headers_.push_back(std::make_pair("ContentType", "application/json")); if (context->req_.keep_alive_) { char buf[100]; context->rsp_.headers_.push_back(std::make_pair("Connection", "keep-alive")); sprintf(buf, "timeout=%d", 100); context->rsp_.headers_.push_back(std::make_pair("Keep-Alive", buf)); } else { context->rsp_.headers_.push_back(std::make_pair("Connection", "close")); } std::ostringstream oss; oss << context->rsp_; boost::asio::async_write(socket_, boost::asio::const_buffers_1(oss.str().data(), oss.str().size()), boost::fibers::asio::yield); FIBP_THREAD_MARK_LOG(0); after_write(context); }