本文整理汇总了C++中DatagramIterator::read_datagram方法的典型用法代码示例。如果您正苦于以下问题:C++ DatagramIterator::read_datagram方法的具体用法?C++ DatagramIterator::read_datagram怎么用?C++ DatagramIterator::read_datagram使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatagramIterator
的用法示例。
在下文中一共展示了DatagramIterator::read_datagram方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
//.........这里部分代码省略.........