本文整理汇总了C++中DatagramIterator::read_string方法的典型用法代码示例。如果您正苦于以下问题:C++ DatagramIterator::read_string方法的具体用法?C++ DatagramIterator::read_string怎么用?C++ DatagramIterator::read_string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatagramIterator
的用法示例。
在下文中一共展示了DatagramIterator::read_string方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handle_datagram
// handle_datagram is the handler for datagrams received from the Astron cluster
void Client::handle_datagram(DatagramHandle in_dg, DatagramIterator &dgi)
{
lock_guard<recursive_mutex> lock(m_client_lock);
if(is_terminated()) {
return;
}
channel_t sender = dgi.read_channel();
if(sender == m_channel) {
return; // ignore messages from ourselves
}
uint16_t msgtype = dgi.read_uint16();
switch(msgtype) {
case CLIENTAGENT_EJECT: {
uint16_t reason = dgi.read_uint16();
string error_string = dgi.read_string();
send_disconnect(reason, error_string);
return;
}
break;
case CLIENTAGENT_DROP: {
handle_drop();
return;
}
break;
case CLIENTAGENT_SET_STATE: {
m_state = (ClientState)dgi.read_uint16();
}
break;
case CLIENTAGENT_ADD_INTEREST: {
uint32_t context = m_next_context++;
Interest i;
build_interest(dgi, false, i);
handle_add_interest(i, context);
add_interest(i, context, sender);
}
break;
case CLIENTAGENT_ADD_INTEREST_MULTIPLE: {
uint32_t context = m_next_context++;
Interest i;
build_interest(dgi, true, i);
handle_add_interest(i, context);
add_interest(i, context, sender);
}
break;
case CLIENTAGENT_REMOVE_INTEREST: {
uint32_t context = m_next_context++;
uint16_t id = dgi.read_uint16();
Interest &i = m_interests[id];
handle_remove_interest(id, context);
remove_interest(i, context, sender);
}
break;
case CLIENTAGENT_SET_CLIENT_ID: {
if(m_channel != m_allocated_channel) {
unsubscribe_channel(m_channel);
}
m_channel = dgi.read_channel();
subscribe_channel(m_channel);
}
break;
case CLIENTAGENT_SEND_DATAGRAM: {
DatagramPtr forward = Datagram::create();
forward->add_data(dgi.read_string());
forward_datagram(forward);
}
break;
case CLIENTAGENT_OPEN_CHANNEL: {
subscribe_channel(dgi.read_channel());
}
break;
case CLIENTAGENT_CLOSE_CHANNEL: {
unsubscribe_channel(dgi.read_channel());
}
break;
case CLIENTAGENT_ADD_POST_REMOVE: {
add_post_remove(m_allocated_channel, dgi.read_datagram());
}
break;
case CLIENTAGENT_CLEAR_POST_REMOVES: {
clear_post_removes(m_allocated_channel);
}
break;
case CLIENTAGENT_DECLARE_OBJECT: {
doid_t do_id = dgi.read_doid();
uint16_t dc_id = dgi.read_uint16();
if(m_declared_objects.find(do_id) != m_declared_objects.end()) {
m_log->warning() << "Received object declaration for previously declared object "
<< do_id << ".\n";
return;
}
DeclaredObject obj;
//.........这里部分代码省略.........
示例2: handle_datagram
// handle_datagram is the handler for datagrams received from the Astron cluster
void Client::handle_datagram(DatagramHandle, DatagramIterator &dgi)
{
std::lock_guard<std::recursive_mutex> lock(m_client_lock);
channel_t sender = dgi.read_channel();
uint16_t msgtype = dgi.read_uint16();
switch(msgtype) {
case CLIENTAGENT_EJECT: {
uint16_t reason = dgi.read_uint16();
std::string error_string = dgi.read_string();
send_disconnect(reason, error_string);
return;
}
break;
case CLIENTAGENT_DROP: {
handle_drop();
return;
}
break;
case CLIENTAGENT_SET_STATE: {
m_state = (ClientState)dgi.read_uint16();
}
break;
case CLIENTAGENT_ADD_INTEREST: {
uint32_t context = m_next_context++;
Interest i;
build_interest(dgi, false, i);
handle_add_interest(i, context);
add_interest(i, context, sender);
}
break;
case CLIENTAGENT_ADD_INTEREST_MULTIPLE: {
uint32_t context = m_next_context++;
Interest i;
build_interest(dgi, true, i);
handle_add_interest(i, context);
add_interest(i, context, sender);
}
break;
case CLIENTAGENT_REMOVE_INTEREST: {
uint32_t context = m_next_context++;
uint16_t id = dgi.read_uint16();
Interest &i = m_interests[id];
handle_remove_interest(id, context);
remove_interest(i, context, sender);
}
break;
case CLIENTAGENT_SET_CLIENT_ID: {
if(m_channel != m_allocated_channel) {
unsubscribe_channel(m_channel);
}
m_channel = dgi.read_channel();
subscribe_channel(m_channel);
}
break;
case CLIENTAGENT_SEND_DATAGRAM: {
DatagramPtr forward = Datagram::create();
forward->add_data(dgi.read_string());
forward_datagram(forward);
}
break;
case CLIENTAGENT_OPEN_CHANNEL: {
subscribe_channel(dgi.read_channel());
}
break;
case CLIENTAGENT_CLOSE_CHANNEL: {
unsubscribe_channel(dgi.read_channel());
}
break;
case CLIENTAGENT_ADD_POST_REMOVE: {
add_post_remove(dgi.read_datagram());
}
break;
case CLIENTAGENT_CLEAR_POST_REMOVES: {
clear_post_removes();
}
break;
case CLIENTAGENT_DECLARE_OBJECT: {
doid_t do_id = dgi.read_doid();
uint16_t dc_id = dgi.read_uint16();
if(m_declared_objects.find(do_id) != m_declared_objects.end()) {
m_log->warning() << "Received object declaration for previously declared object "
<< do_id << ".\n";
return;
}
DeclaredObject obj;
obj.id = do_id;
obj.dcc = g_dcf->get_class_by_id(dc_id);
m_declared_objects[do_id] = obj;
}
break;
case CLIENTAGENT_UNDECLARE_OBJECT: {
doid_t do_id = dgi.read_doid();
//.........这里部分代码省略.........
示例3: handle_datagram
virtual void handle_datagram(Datagram &dg, DatagramIterator &dgi)
{
gLogger->log(LogSeverity::LSEVERITY_DEBUG) << dgi.read_string() << std::endl;
}
示例4: str
static BSONObj bamboo2bson(const dclass::DistributedType *type,
DatagramIterator &dgi)
{
// The BSON library's weird data model doesn't allow elements to exist on
// their own; they must be part of an object. Therefore, we always return
// results in a single BSONObj with key "_"
BSONObjBuilder b;
switch(type->get_type()) {
case dclass::Type::T_INT8: {
b << "_" << dgi.read_int8();
}
break;
case dclass::Type::T_INT16: {
b << "_" << dgi.read_int16();
}
break;
case dclass::Type::T_INT32: {
b << "_" << dgi.read_int32();
}
break;
case dclass::Type::T_INT64: {
b.appendIntOrLL("_", dgi.read_int64());
}
break;
case dclass::Type::T_UINT8: {
b << "_" << dgi.read_uint8();
}
break;
case dclass::Type::T_UINT16: {
b << "_" << dgi.read_uint16();
}
break;
case dclass::Type::T_UINT32: {
b << "_" << dgi.read_uint32();
}
break;
case dclass::Type::T_UINT64: {
b.appendIntOrLL("_", dgi.read_uint64());
}
break;
case dclass::Type::T_CHAR: {
unsigned char c = dgi.read_uint8();
string str(c, 1);
b << "_" << str;
}
break;
case dclass::Type::T_FLOAT32: {
b << "_" << dgi.read_float32();
}
break;
case dclass::Type::T_FLOAT64: {
b << "_" << dgi.read_float64();
}
break;
case dclass::Type::T_STRING: {
vector<uint8_t> vec = dgi.read_data(type->get_size());
string str((const char *)vec.data(), vec.size());
b << "_" << str;
}
case dclass::Type::T_VARSTRING: {
b << "_" << dgi.read_string();
}
break;
case dclass::Type::T_BLOB: {
vector<uint8_t> blob = dgi.read_data(type->get_size());
b.appendBinData("_", blob.size(), BinDataGeneral, blob.data());
}
break;
case dclass::Type::T_VARBLOB: {
vector<uint8_t> blob = dgi.read_blob();
b.appendBinData("_", blob.size(), BinDataGeneral, blob.data());
}
break;
case dclass::Type::T_ARRAY: {
const dclass::ArrayType *array = type->as_array();
BSONArrayBuilder ab;
for(size_t i = 0; i < array->get_array_size(); i++) {
ab << bamboo2bson(array->get_element_type(), dgi)["_"];
}
b << "_" << ab.arr();
}
break;
case dclass::Type::T_VARARRAY: {
const dclass::ArrayType *array = type->as_array();
dgsize_t array_length = dgi.read_size();
dgsize_t starting_size = dgi.tell();
BSONArrayBuilder ab;
while(dgi.tell() != starting_size + array_length) {
ab << bamboo2bson(array->get_element_type(), dgi)["_"];
if(dgi.tell() > starting_size + array_length) {
throw mongo::DBException("Discovered corrupt array-length tag!", 0);
}
}
//.........这里部分代码省略.........
示例5: handle_datagram
// handle_datagram is the handler for datagrams received from the Astron cluster
void Client::handle_datagram(Datagram &dg, DatagramIterator &dgi)
{
channel_t sender = dgi.read_uint64();
uint16_t msgtype = dgi.read_uint16();
switch(msgtype)
{
case CLIENTAGENT_EJECT:
{
uint16_t reason = dgi.read_uint16();
std::string error_string = dgi.read_string();
send_disconnect(reason, error_string);
return;
}
break;
case CLIENTAGENT_DROP:
{
handle_drop();
return;
}
break;
case CLIENTAGENT_SET_STATE:
{
m_state = (ClientState)dgi.read_uint16();
}
break;
case STATESERVER_OBJECT_SET_FIELD:
{
uint32_t do_id = dgi.read_uint32();
if(!lookup_object(do_id))
{
m_log->warning() << "Received server-side field update for unknown object " << do_id << std::endl;
return;
}
if(sender != m_channel)
{
uint16_t field_id = dgi.read_uint16();
handle_set_field(do_id, field_id, dgi);
}
}
break;
case STATESERVER_OBJECT_DELETE_RAM:
{
uint32_t do_id = dgi.read_uint32();
if(!lookup_object(do_id))
{
m_log->warning() << "Received server-side object delete for unknown object " << do_id << std::endl;
return;
}
if(m_seen_objects.find(do_id) != m_seen_objects.end())
{
m_seen_objects.erase(do_id);
m_id_history.insert(do_id);
handle_remove_object(do_id);
}
if(m_owned_objects.find(do_id) != m_owned_objects.end())
{
m_owned_objects.erase(do_id);
handle_remove_ownership(do_id);
}
m_dist_objs.erase(do_id);
}
break;
case STATESERVER_OBJECT_ENTER_OWNER_WITH_REQUIRED_OTHER:
case STATESERVER_OBJECT_ENTER_OWNER_WITH_REQUIRED:
{
uint32_t do_id = dgi.read_uint32();
uint32_t parent = dgi.read_uint32();
uint32_t zone = dgi.read_uint32();
uint16_t dc_id = dgi.read_uint16();
m_owned_objects.insert(do_id);
if(m_dist_objs.find(do_id) == m_dist_objs.end())
{
VisibleObject obj;
obj.id = do_id;
obj.parent = parent;
obj.zone = zone;
obj.dcc = g_dcf->get_class(dc_id);
m_dist_objs[do_id] = obj;
}
handle_add_ownership(do_id, parent, zone, dc_id, dgi, true);
}
break;
case CLIENTAGENT_SET_CLIENT_ID:
{
if(m_channel != m_allocated_channel)
{
unsubscribe_channel(m_channel);
}
m_channel = dgi.read_uint64();
subscribe_channel(m_channel);
}
break;
case CLIENTAGENT_SEND_DATAGRAM:
//.........这里部分代码省略.........