Skip to content

Commit

Permalink
fix sonar code smell.
Browse files Browse the repository at this point in the history
  • Loading branch information
freeeyes committed Oct 8, 2023
1 parent 6045e87 commit 919f80f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
45 changes: 25 additions & 20 deletions PSS_ASIO/TcpSession/TcpSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,30 +166,35 @@ void CTcpSession::do_write(uint32 connect_id)
asio::async_write(self->socket_, asio::buffer(send_buffer->data_.c_str(), send_buffer->buffer_length_),
[self, send_buffer, connect_id](std::error_code ec, std::size_t length)
{
if (ec)
{
//发送写入消息失败信息
PSS_LOGGER_DEBUG("[CTcpSession::do_write]({0})write error({1}).", connect_id, ec.message());
self->send_write_fail_to_logic(send_buffer->data_, length);
if (true == self->is_active_close_)
{
self->close_immediaterly();
}
}
else
{
self->add_send_finish_size(connect_id, length);
if (true == self->is_active_close_
&& self->send_buffer_size_ == self->send_data_size_)
{
//关闭客户端
self->close_immediaterly();
}
}
self->do_write_finish(ec, connect_id, send_buffer, length);
});
});
}

void CTcpSession::do_write_finish(std::error_code& ec, uint32 connect_id, std::shared_ptr<CSendBuffer> send_buffer, std::size_t length)
{
if (ec)
{
//发送写入消息失败信息
PSS_LOGGER_DEBUG("[CTcpSession::do_write]({0})write error({1}).", connect_id, ec.message());
send_write_fail_to_logic(send_buffer->data_, length);
if (true == is_active_close_)
{
close_immediaterly();
}
}
else
{
add_send_finish_size(connect_id, length);
if (true == is_active_close_
&& send_buffer_size_ == send_data_size_)
{
//关闭客户端
close_immediaterly();
}
}
}

void CTcpSession::do_write_immediately(uint32 connect_id, const char* data, size_t length)
{
set_write_buffer(connect_id, data, length);
Expand Down
2 changes: 2 additions & 0 deletions PSS_ASIO/TcpSession/TcpSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class CTcpSession : public std::enable_shared_from_this<CTcpSession>, public ISe

void send_write_fail_to_logic(const std::string& write_fail_buffer, std::size_t buffer_length);

void do_write_finish(std::error_code& ec, uint32 connect_id, std::shared_ptr<CSendBuffer> send_buffer, std::size_t length);

private:
tcp::socket socket_;
asio::io_context* io_context_ = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion PSS_ASIO/UdpSession/KcpServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class CKcpServer : public std::enable_shared_from_this<CKcpServer>, public ISess
public:
CKcpServer(asio::io_context* io_context, const std::string& server_ip, io_port_type port, uint32 packet_parse_id, uint32 max_recv_size, uint32 max_send_size, CIo_List_Manager* io_list_manager);

virtual ~CKcpServer() = default;
~CKcpServer() override = default;

void start();

Expand Down
1 change: 0 additions & 1 deletion PSS_ASIO/UdpSession/UdpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ void CUdpServer::do_receive()
EM_CONNECT_IO_TYPE::CONNECT_IO_UDP);

self->io_list_manager_->del_accept_net_io_event(self->server_ip_, self->server_port_, EM_CONNECT_IO_TYPE::CONNECT_IO_UDP);
return;
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion PSS_ASIO/UdpSession/UdpServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CUdpServer : public std::enable_shared_from_this<CUdpServer>, public ISess
public:
CUdpServer(asio::io_context* io_context, const std::string& server_ip, io_port_type port, uint32 packet_parse_id, uint32 max_recv_size, uint32 max_send_size, EM_NET_TYPE em_net_type, CIo_List_Manager* io_list_manager);

virtual ~CUdpServer() = default;
~CUdpServer() override = default;

void start();

Expand Down

0 comments on commit 919f80f

Please sign in to comment.