本文整理汇总了C++中session类的典型用法代码示例。如果您正苦于以下问题:C++ session类的具体用法?C++ session怎么用?C++ session使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_cache_timestamp
static void test_cache_timestamp(session &sess)
{
argument_data data("this is a timestamp test");
key k("this is a timestamp test key");
sess.transform(k);
dnet_io_control ctl;
memset(&ctl, 0, sizeof(ctl));
ctl.data = data.data();
dnet_current_time(&ctl.io.timestamp);
ctl.io.flags = DNET_IO_FLAGS_CACHE;
ctl.io.start = 5;
ctl.io.size = data.size();
memcpy(&ctl.id, &k.id(), sizeof(dnet_id));
ctl.fd = -1;
ELLIPTICS_REQUIRE(write_result, sess.write_data(ctl));
sleep(ctl.io.start + 2);
ELLIPTICS_REQUIRE(read_result, sess.read_data(k, 0, 0));
auto io = read_result.get_one().io_attribute();
BOOST_REQUIRE_EQUAL(io->timestamp.tsec, ctl.io.timestamp.tsec);
BOOST_REQUIRE_EQUAL(io->timestamp.tnsec, ctl.io.timestamp.tnsec);
}
示例2: m_data
async_result<T>::async_result(const session &sess) : m_data(std::make_shared<data>())
{
m_data->filter = sess.get_filter();
m_data->checker = sess.get_checker();
m_data->policy = sess.get_exceptions_policy();
m_data->error_handler = sess.get_error_handler();
}
示例3: test_direct_backend
static void test_direct_backend(session &sess)
{
const key id = std::string("direct-backend-test");
sess.set_groups({ 0 });
const std::string first_str = "first-data";
const std::string second_str = "second-data";
server_node &node = global_data->nodes.front();
session first = sess.clone();
first.set_direct_id(node.remote(), 0);
session second = sess.clone();
second.set_direct_id(node.remote(), 3);
ELLIPTICS_REQUIRE(async_first_write, first.write_data(id, first_str, 0));
ELLIPTICS_REQUIRE(async_second_write, second.write_data(id, second_str, 0));
ELLIPTICS_REQUIRE(async_first_read, first.read_data(id, 0, 0));
read_result_entry first_read = async_first_read.get_one();
BOOST_REQUIRE_EQUAL(first_read.file().to_string(), first_str);
BOOST_REQUIRE_EQUAL(first_read.command()->backend_id, 0);
ELLIPTICS_REQUIRE(async_second_read, second.read_data(id, 0, 0));
read_result_entry second_read = async_second_read.get_one();
BOOST_REQUIRE_EQUAL(second_read.file().to_string(), second_str);
BOOST_REQUIRE_EQUAL(second_read.command()->backend_id, 3);
}
示例4: test_set_backend_ids_for_disabled
static void test_set_backend_ids_for_disabled(session &sess)
{
server_node &node = global_data->nodes.back();
auto ids = generate_ids(16);
ELLIPTICS_REQUIRE(async_set_result, sess.set_backend_ids(node.remote(), 4, ids));
backend_status_result_entry result = async_set_result.get_one();
BOOST_REQUIRE(result.is_valid());
BOOST_REQUIRE_EQUAL(result.count(), 1);
dnet_backend_status *status = result.backend(0);
BOOST_REQUIRE_EQUAL(status->backend_id, 4);
BOOST_REQUIRE_EQUAL(status->state, DNET_BACKEND_DISABLED);
ELLIPTICS_REQUIRE(async_enable_result, sess.enable_backend(node.remote(), 4));
// Wait 0.1 secs to ensure that route list was changed
usleep(100 * 1000);
auto route_ids = backend_ids(sess, node.remote(), 4);
BOOST_REQUIRE_EQUAL(ids.size(), route_ids.size());
BOOST_REQUIRE(compare_ids(ids, route_ids));
}
示例5: test_cache_overflow
static void test_cache_overflow(session &sess)
{
ioremap::cache::cache_manager *cache = (ioremap::cache::cache_manager*) global_data->nodes[0].get_native()->cache;
const size_t cache_size = cache->cache_size();
const size_t cache_pages_number = cache->cache_pages_number();
argument_data data("0");
cache->clear();
size_t record_size = 0;
{
ELLIPTICS_REQUIRE(write_result, sess.write_cache(key(std::string("0")), data, 3000));
const auto& stats = cache->get_total_cache_stats();
record_size = stats.size_of_objects;
}
size_t records_number = (cache_size / cache_pages_number / record_size) * 10;
for (size_t id = 1; id < records_number; ++id) {
ELLIPTICS_REQUIRE(write_result, sess.write_cache(key(boost::lexical_cast<std::string>(id)), data, 3000));
const auto& stats = cache->get_total_cache_stats();
size_t total_pages_sizes = 0;
for (size_t i = 0; i < stats.pages_sizes.size(); ++i) {
total_pages_sizes += stats.pages_sizes[i];
// BOOST_REQUIRE_LE(stats.pages_sizes[i], stats.pages_max_sizes[i]);
}
// BOOST_REQUIRE_LE(stats.size_of_objects, cache_size);
// BOOST_REQUIRE_EQUAL(stats.size_of_objects, total_pages_sizes);
}
}
示例6: test_cache_records_sizes
static void test_cache_records_sizes(session &sess, const nodes_data *setup)
{
dnet_node *node = setup->nodes[0].get_native();
dnet_backend_io *backend_io = dnet_get_backend_io(node->io, 0);
ioremap::cache::cache_manager *cache = reinterpret_cast<ioremap::cache::cache_manager *>(backend_io->cache);
const size_t cache_size = cache->cache_size();
const size_t cache_pages_number = cache->cache_pages_number();
argument_data data("0");
cache->clear();
size_t record_size = 0;
{
ELLIPTICS_REQUIRE(write_result, sess.write_cache(key(boost::lexical_cast<std::string>(0)), data, 3000));
auto stats = cache->get_total_cache_stats();
record_size = stats.size_of_objects;
BOOST_REQUIRE_EQUAL(stats.number_of_objects, 1);
}
size_t records_number = cache_size / cache_pages_number / record_size - 5;
for (size_t id = 1; id < records_number; ++id) {
ELLIPTICS_REQUIRE(write_result,
sess.write_cache(key(boost::lexical_cast<std::string>(id)), data, 3000));
auto stats = cache->get_total_cache_stats();
size_t total_pages_sizes = 0;
for (size_t i = 0; i < stats.pages_sizes.size(); ++i) {
total_pages_sizes += stats.pages_sizes[i];
}
BOOST_REQUIRE_EQUAL(stats.number_of_objects * record_size, stats.size_of_objects);
BOOST_REQUIRE_EQUAL(stats.number_of_objects, id + 1);
BOOST_REQUIRE_EQUAL(stats.size_of_objects, total_pages_sizes);
}
}
示例7: table_creator_2
table_creator_2(session & sql)
: tests::table_creator_base(sql)
{
sql << "create table soci_test(\"num_float\" float, \"num_int\" integer, "
"\"name\" varchar(20), \"sometime\" timestamp, \"chr\" char)";
sql.commit();
sql.begin();
}
示例8: table_creator_1
table_creator_1(session & sql)
: tests::table_creator_base(sql)
{
sql << "create table soci_test(id integer, val integer, c char, "
"str varchar(20), sh smallint, ul decimal(9,0), d double precision, "
"tm timestamp, i1 integer, i2 integer, i3 integer, name varchar(20))";
sql.commit();
sql.begin();
}
示例9: table_creator_3
table_creator_3(session & sql)
: tests::table_creator_base(sql)
{
// CommonTest uses lower-case column names,
// so we need to enforce such names here.
// That's why column names are enclosed in ""
sql << "create table soci_test(\"name\" varchar(100) not null, "
"\"phone\" varchar(15))";
sql.commit();
sql.begin();
}
示例10: init_application_impl
static void init_application_impl(session &sess, const std::string &app_name, nodes_data &data)
{
node_info info = node_info::create(data, sess.get_groups());
ELLIPTICS_REQUIRE(exec_result, sess.exec(NULL, app_name + "@init", info.pack()));
sync_exec_result result = exec_result;
BOOST_REQUIRE_EQUAL(result.size(), data.nodes.size());
for (auto it = result.begin(); it != result.end(); ++it)
BOOST_REQUIRE_EQUAL(it->context().data().to_string(), "inited");
}
示例11: test_error_message
static void test_error_message(session &s, const std::string &id, int err)
{
s.set_filter(filters::all);
ELLIPTICS_REQUIRE_ERROR(read_result, s.read_data(id, 0, 0), err);
sync_read_result sync_result = read_result.get();
BOOST_REQUIRE(sync_result.size() > 0);
read_result_entry entry = sync_result[0];
BOOST_REQUIRE_EXCEPTION(entry.io_attribute(), not_found_error, test_error_check_exception);
}
示例12: init_application_impl
void init_application_impl(session &sess, const std::string &app_name, const nodes_data *setup)
{
sess.set_timeout(600);
auto log = sess.get_logger();
DNET_LOG_INFO(log, "Sending @init");
node_info info = node_info_create(setup, sess.get_groups());
ELLIPTICS_REQUIRE(exec_result, sess.exec(NULL, app_name + "@init", info.pack()));
sync_exec_result result = exec_result;
BOOST_REQUIRE_EQUAL(result.size(), setup->nodes.size());
for (auto it = result.begin(); it != result.end(); ++it)
BOOST_REQUIRE_EQUAL(it->context().data().to_string(), "inited");
}
示例13: session_
statement_impl::statement_impl(session & s)
: session_(s), refCount_(1), row_(0),
fetchSize_(1), initialFetchSize_(1),
alreadyDescribed_(false)
{
backEnd_ = s.make_statement_backend();
}
示例14: add_magnet_uri
torrent_handle add_magnet_uri(session& ses, std::string const& uri
, add_torrent_params p)
{
std::string name;
std::string tracker;
boost::optional<std::string> display_name = url_has_argument(uri, "dn");
if (display_name) name = unescape_string(display_name->c_str());
boost::optional<std::string> tracker_string = url_has_argument(uri, "tr");
if (tracker_string) tracker = unescape_string(tracker_string->c_str());
boost::optional<std::string> btih = url_has_argument(uri, "xt");
if (!btih) return torrent_handle();
if (btih->compare(0, 9, "urn:btih:") != 0) return torrent_handle();
sha1_hash info_hash;
if (btih->size() == 40 + 9) info_hash = boost::lexical_cast<sha1_hash>(btih->substr(9));
else info_hash.assign(base32decode(btih->substr(9)));
if (!tracker.empty()) p.tracker_url = tracker.c_str();
p.info_hash = info_hash;
if (!name.empty()) p.name = name.c_str();
return ses.add_torrent(p);
}
示例15: add_magnet_uri
torrent_handle add_magnet_uri(session& ses, std::string const& uri
, std::string const& save_path
, storage_mode_t storage_mode
, bool paused
, storage_constructor_type sc
, void* userdata)
{
std::string name;
std::string tracker;
error_code ec;
std::string display_name = url_has_argument(uri, "dn");
if (!display_name.empty()) name = unescape_string(display_name.c_str(), ec);
std::string tracker_string = url_has_argument(uri, "tr");
if (!tracker_string.empty()) tracker = unescape_string(tracker_string.c_str(), ec);
std::string btih = url_has_argument(uri, "xt");
if (btih.empty()) return torrent_handle();
if (btih.compare(0, 9, "urn:btih:") != 0) return torrent_handle();
sha1_hash info_hash;
if (btih.size() == 40 + 9) from_hex(&btih[9], 40, (char*)&info_hash[0]);
else info_hash.assign(base32decode(btih.substr(9)));
return ses.add_torrent(tracker.empty() ? 0 : tracker.c_str(), info_hash
, name.empty() ? 0 : name.c_str(), save_path, entry()
, storage_mode, paused, sc, userdata);
}