Skip to content

Commit 2d342eb

Browse files
committed
use weak_ptr for ping check.
1 parent 88a7506 commit 2d342eb

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/brynet/net/DataSocket.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ namespace brynet { namespace net {
576576
}
577577
if (mPostWriteCheck)
578578
{
579-
CancelIoEx(HANDLE(mSocket->getFD()), &mOvlRecv.base);
579+
CancelIoEx(HANDLE(mSocket->getFD()), &mOvlSend.base);
580580
}
581581
}
582582
else
@@ -763,9 +763,13 @@ namespace brynet { namespace net {
763763
{
764764
if (!mTimer.lock() && mCheckTime != std::chrono::steady_clock::duration::zero())
765765
{
766-
auto sharedThis = shared_from_this();
767-
mTimer = mEventLoop->getTimerMgr()->addTimer(mCheckTime, [sharedThis]() {
768-
sharedThis->PingCheck();
766+
std::weak_ptr<DataSocket> weakedThis = shared_from_this();
767+
mTimer = mEventLoop->getTimerMgr()->addTimer(mCheckTime, [weakedThis]() {
768+
auto sharedThis = weakedThis.lock();
769+
if (sharedThis != nullptr)
770+
{
771+
sharedThis->PingCheck();
772+
}
769773
});
770774
}
771775
}

0 commit comments

Comments
 (0)