Skip to content

Commit

Permalink
修订临时连接断开时的log
Browse files Browse the repository at this point in the history
  • Loading branch information
owent committed Mar 6, 2024
1 parent be2fe17 commit 5772d23
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion atframework/atframe_utils
1 change: 1 addition & 0 deletions include/atbus_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class connection final : public util::design_pattern::noncopyable {
DESTRUCTING, /** 正在执行析构(屏蔽某些接口) **/
LISTEN_FD, /** 是否是用于listen的连接 **/
TEMPORARY, /** 是否是临时连接 **/
PEER_CLOSED, /** 对端已关闭 **/
MAX
};
};
Expand Down
3 changes: 3 additions & 0 deletions src/atbus_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,9 @@ ATBUS_MACRO_API void connection::iostream_on_recv_cb(channel::io_stream_channel
connection *conn = reinterpret_cast<connection *>(conn_ios->data);

if (status < 0 || nullptr == buffer || s <= 0) {
if (nullptr != conn && (UV_EOF == channel->error_code || UV_ECONNRESET == channel->error_code)) {
conn->flags_.set(flag_t::PEER_CLOSED, true);
}
::atbus::protocol::msg m;
_this->on_recv(conn, ATBUS_MACRO_MOVE(m), status, channel->error_code);
return;
Expand Down
10 changes: 8 additions & 2 deletions src/atbus_msg_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,6 @@ ATBUS_MACRO_API int msg_handler::on_recv_node_reg_rsp(node &n, connection *conn,
}

endpoint *ep = conn->get_binding();
n.on_reg(ep, conn, m.head().ret());

// Check access token
bool check_access_token = true;
Expand Down Expand Up @@ -1067,9 +1066,16 @@ ATBUS_MACRO_API int msg_handler::on_recv_node_reg_rsp(node &n, connection *conn,
ATBUS_FUNC_NODE_ERROR(n, ep, conn, ret_code, errcode);
} while (false);

n.on_reg(ep, conn, ret_code);

conn->reset();
return ret_code;
} else if (node::state_t::CONNECTING_PARENT == n.get_state()) {
}

// 注册事件触发
n.on_reg(ep, conn, m.head().ret());

if (node::state_t::CONNECTING_PARENT == n.get_state()) {
// 父节点返回的rsp成功则可以上线
// 这时候父节点的endpoint不一定初始化完毕
if (n.is_parent_node(reg_data->bus_id())) {
Expand Down
8 changes: 6 additions & 2 deletions src/atbus_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1452,8 +1452,12 @@ ATBUS_MACRO_API bool node::remove_connection_timer(timer_desc_ls<connection::ptr
}

if (event_msg_.on_invalid_connection && out->second && !out->second->is_connected()) {
flag_guard_t fgd(this, flag_t::EN_FT_IN_CALLBACK);
event_msg_.on_invalid_connection(std::cref(*this), out->second.get(), EN_ATBUS_ERR_NODE_TIMEOUT);
// 确认的临时连接断开不属于无效连接
if (!out->second->check_flag(connection::flag_t::TEMPORARY) ||
!out->second->check_flag(connection::flag_t::PEER_CLOSED)) {
flag_guard_t fgd(this, flag_t::EN_FT_IN_CALLBACK);
event_msg_.on_invalid_connection(std::cref(*this), out->second.get(), EN_ATBUS_ERR_NODE_TIMEOUT);
}
}

event_timer_.connecting_list.erase(out);
Expand Down

0 comments on commit 5772d23

Please sign in to comment.