void S1mmeSession::CheckTimeout(uint64_t second, uint8_t worker_id) { //主map 超时, 同时伴随 辅助map 超时 bool dead_loop_major,dead_loop_hoc,dead_loop_stmsi; { S1APNode* p_cur = (S1APNode*)(p_major_map_->GetHead()); S1APKey_T* p_cur_key = p_major_map_->GetCursorKey(); S1APNode* p_next = (S1APNode*)(p_major_map_->Next()); S1APKey_T* p_next_key = p_major_map_->GetCursorKey(); while (p_next != NULL) { if (current_time_.tv_sec - p_cur->GetLastTime().tv_sec > timeout_major_) { if (handle_session_version_ == S1MME_SESSION_VERSION_CHINA_TELECOM) { CtOutputNode(p_cur,true); } else { CuOutputNode(p_cur,s1mme_worker_id_,true); } p_path_switch_map_->DeleteData(p_cur->GetMMEKey(), p_s1ap_node_allocator_); p_handover_container_map_->DeleteData(p_cur->GetContainerKey(), p_s1ap_node_allocator_); SPUserInfo& sp_user_info = p_cur->GetUserInfo(); //Todo@ydzy:超时stmsi map p_major_map->DeleteData(p_cur_key, p_s1ap_node_allocator_); p_cur = p_next; p_next = (S1APNode)(p_major_map_->Next()); p_cur_key = p_next_key; p_next_key = p_major_map_->GetCursorKey(); } else { break; } } dead_loop_major = p_major_map_->CheckDeadLoop(); }在S1mmeSession::CheckTimeout函数中增加一个超时处理函数,超时处理函数遍历新增加的hash节点,当current_time_.tv_sec-节点的last_time时,使用LogInfo函数将节点所有字段以及current_time_.tv_sec字段进行输出
时间: 2024-03-26 08:35:33 浏览: 120
好的,我理解了您的要求。以下是在S1mmeSession::CheckTimeout函数中增加一个超时处理函数的代码示例:
```
void S1mmeSession::CheckTimeout(uint64_t second, uint8_t worker_id) {
//主map 超时, 同时伴随 辅助map 超时
bool dead_loop_major,dead_loop_hoc,dead_loop_stmsi;
{
S1APNode* p_cur = (S1APNode*)(p_major_map_->GetHead());
S1APKey_T* p_cur_key = p_major_map_->GetCursorKey();
S1APNode* p_next = (S1APNode*)(p_major_map_->Next());
S1APKey_T* p_next_key = p_major_map_->GetCursorKey();
while (p_next != NULL) {
if (current_time_.tv_sec - p_cur->GetLastTime().tv_sec > timeout_major_) {
if (handle_session_version_ == S1MME_SESSION_VERSION_CHINA_TELECOM) {
CtOutputNode(p_cur,true);
} else {
CuOutputNode(p_cur,s1mme_worker_id_,true);
}
p_path_switch_map_->DeleteData(p_cur->GetMMEKey(), p_s1ap_node_allocator_);
p_handover_container_map_->DeleteData(p_cur->GetContainerKey(), p_s1ap_node_allocator_);
SPUserInfo& sp_user_info = p_cur->GetUserInfo();
//Todo@ydzy:超时stmsi map
p_major_map_->DeleteData(p_cur_key, p_s1ap_node_allocator_);
// 增加超时处理函数
if (current_time_.tv_sec - p_cur->GetLastTime().tv_sec > timeout_new_hash_node_) {
LogInfo("超时处理函数:节点超时,当前时间:%llu,节点信息:{字段1:%d,字段2:%d,字段3:%s}。",
current_time_.tv_sec, p_cur->GetField1(), p_cur->GetField2(), p_cur->GetField3().c_str());
}
p_cur = p_next;
p_next = (S1APNode)(p_major_map_->Next());
p_cur_key = p_next_key;
p_next_key = p_major_map_->GetCursorKey();
} else {
break;
}
}
dead_loop_major = p_major_map_->CheckDeadLoop();
}
}
```
其中,超时处理函数的代码如下:
```
if (current_time_.tv_sec - p_cur->GetLastTime().tv_sec > timeout_new_hash_node_) {
LogInfo("超时处理函数:节点超时,当前时间:%llu,节点信息:{字段1:%d,字段2:%d,字段3:%s}。",
current_time_.tv_sec, p_cur->GetField1(), p_cur->GetField2(), p_cur->GetField3().c_str());
}
```
当节点的last_time字段与当前时间的时间差大于timeout_new_hash_node_时,超时处理函数会将该节点的字段以及当前时间输出到日志中。您可以根据需要自行修改输出内容和格式。
阅读全文