Skip to content

Commit

Permalink
check io mapping logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchao412 committed Feb 27, 2024
1 parent af06d64 commit e66f79c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
41 changes: 30 additions & 11 deletions PSS_ASIO/Message/IotoIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,19 @@
bool CIotoIo::add_session_io_mapping(const _ClientIPInfo& from_io, EM_CONNECT_IO_TYPE from_io_type, const _ClientIPInfo& to_io, EM_CONNECT_IO_TYPE to_io_type, ENUM_IO_BRIDGE_TYPE bridge_type)
{
std::lock_guard <std::mutex> lock(mutex_);
for (const auto& Connect_Info : io_2_io_list_)
{
if (true == compare_connect_io(from_io, from_io_type, Connect_Info.from_io_, Connect_Info.from_io_type_))
{
//点对点链接已存在,不能添加
PSS_LOGGER_DEBUG("[CIotoIo::add_session_io_mapping]from_io={}:{} is exist.", from_io.m_strClientIP, from_io.m_u2Port);
return false;
}
}

//添加新的映射
CIo_Connect_Info connect_info;
connect_info.from_io_ = from_io;
connect_info.from_io_type_ = from_io_type;
connect_info.to_io_ = to_io;
connect_info.to_io_type_ = to_io_type;
connect_info.bridge_type_ = bridge_type;

if(0 != this->check_io_mapping(connect_info))
{
return false;
}

//添加新的映射
io_2_io_list_.emplace_back(connect_info);

//这里需要注意,在add的时候,可能链接已经存在了,
Expand Down Expand Up @@ -220,5 +215,29 @@ bool CIotoIo::compare_connect_io(const _ClientIPInfo& from_io, EM_CONNECT_IO_TYP
}
}

int CIotoIo::check_io_mapping(const CIo_Connect_Info& connect_info)
{
for (const auto& Connect_Info : io_2_io_list_)
{
if (true == compare_connect_io(connect_info.from_io_, connect_info.from_io_type_, Connect_Info.from_io_, Connect_Info.from_io_type_))
{
//点对点链接已存在,不能添加
PSS_LOGGER_WARN("[CIotoIo::check_io_mapping]io mapping duplication,from_io={}:{} is exist.", connect_info.from_io_.m_strClientIP, connect_info.from_io_.m_u2Port);
return 1;
}

if (ENUM_IO_BRIDGE_TYPE::IO_BRIDGE_BATH == connect_info.bridge_type_)
{
if (true == compare_connect_io(connect_info.to_io_, connect_info.to_io_type_, Connect_Info.from_io_, Connect_Info.from_io_type_))
{
//点对点链接已存在,不能添加
PSS_LOGGER_WARN("[CIotoIo::check_io_mapping]io mapping loop,to_io={}:{} is exist.", connect_info.to_io_.m_strClientIP, connect_info.to_io_.m_u2Port);
return 2;
}
}
}

return 0;
}


2 changes: 2 additions & 0 deletions PSS_ASIO/Message/IotoIo.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class CIotoIo

void unlink_io_bridge(const CIo_Connect_Info& io_connect_info);

int check_io_mapping(const CIo_Connect_Info& connect_info);

vector<CIo_Connect_Info> io_2_io_list_;
std::mutex mutex_;
};

0 comments on commit e66f79c

Please sign in to comment.