提交 a6ba7c5b 编写于 作者: Y youngwolf

Compromise with c++17 and c++20 (just in MSVC).

上级 d791e25b
......@@ -67,7 +67,11 @@ using namespace ascs::ext;
//under the default behavior, each tcp::socket has their own packer, and cause memory waste
//at here, we make each echo_socket use the same global packer for memory saving
//notice: do not do this for unpacker, because unpacker has member variables and can't share each other
#if _MSVC_LANG > 201703L
auto global_packer = std::make_shared<ASCS_DEFAULT_PACKER>();
#else
auto global_packer(std::make_shared<ASCS_DEFAULT_PACKER>());
#endif
//demonstrate how to control the type of tcp::server_socket_base::server from template parameter
class i_echo_server : public i_server
......
......@@ -257,7 +257,11 @@ public:
{
std::lock_guard<std::mutex> lock(invalid_object_can_mutex);
auto iter = std::find_if(std::begin(invalid_object_can), std::end(invalid_object_can), [&](object_ctype& item) {return item->is_equal_to(id);});
if (iter != std::end(invalid_object_can) && (*iter).unique() && (*iter)->obsoleted())
#if _MSVC_LANG >= 201703L
if (iter != std::end(invalid_object_can) && 1 == iter->use_count() && (*iter)->obsoleted())
#else
if (iter != std::end(invalid_object_can) && iter->unique() && (*iter)->obsoleted())
#endif
{
auto object_ptr(std::move(*iter));
invalid_object_can.erase(iter);
......@@ -271,7 +275,11 @@ public:
{
std::lock_guard<std::mutex> lock(invalid_object_can_mutex);
for (auto iter = std::begin(invalid_object_can); iter != std::end(invalid_object_can); ++iter)
if ((*iter).unique() && (*iter)->obsoleted())
#if _MSVC_LANG >= 201703L
if (iter->use_count() && (*iter)->obsoleted())
#else
if (iter->unique() && (*iter)->obsoleted())
#endif
{
auto object_ptr(std::move(*iter));
invalid_object_can.erase(iter);
......@@ -332,7 +340,11 @@ public:
// socket_ptr->set_timer(...);
//}
//then in the future, when invoke the timer handler, the socket has been freed and its this pointer already became wild.
if ((*iter).unique() && (*iter)->obsoleted())
#if _MSVC_LANG >= 201703L
if (1 == iter->use_count() && (*iter)->obsoleted())
#else
if (iter->unique() && (*iter)->obsoleted())
#endif
{
--num;
++num_affected;
......
......@@ -69,7 +69,11 @@ public:
{auto ref_holder(aci); return [=](const boost::system::error_code& ec, size_t bytes_transferred) {(void) ref_holder; handler(ec, bytes_transferred);};}
#endif
#if _MSVC_LANG >= 201703L
bool is_async_calling() const {return aci.use_count() > 1;}
#else
bool is_async_calling() const {return !aci.unique();}
#endif
bool is_last_async_call() const {return aci.use_count() <= 2;} //can only be called in callbacks
inline void set_async_calling(bool) {}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册