Skip to content

Commit

Permalink
Merge pull request #235 from pabigot/pr/235
Browse files Browse the repository at this point in the history
cleanup fixes in linux-tcp
  • Loading branch information
EmielBruijntjes authored Jun 24, 2018
2 parents e665916 + 94bff62 commit 6827231
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
20 changes: 19 additions & 1 deletion include/amqpcpp/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,25 @@ class Monitor
Monitor(const Monitor &monitor) : _watchable(monitor._watchable)
{
// register with the watchable
_watchable->add(this);
if (_watchable) _watchable->add(this);
}

/**
* Assignment operator
* @param monitor
*/
Monitor& operator= (const Monitor &monitor)
{
// remove from watchable
if (_watchable) _watchable->remove(this);

// replace watchable
_watchable = monitor._watchable;

// register with the watchable
if (_watchable) _watchable->add(this);

return *this;
}

/**
Expand Down
10 changes: 6 additions & 4 deletions src/linux_tcp/tcpresolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class TcpResolver : public TcpState
* Proceed to the next state
* @return TcpState *
*/
TcpState *proceed()
TcpState *proceed(const Monitor &monitor)
{
// do we have a valid socket?
if (_socket >= 0)
Expand All @@ -211,6 +211,9 @@ class TcpResolver : public TcpState
// report error
_handler->onError(_connection, _error.data());

// handler callback might have destroyed connection
if (!monitor.valid()) return nullptr;

// create dummy implementation
return new TcpClosed(_connection, _handler);
}
Expand All @@ -229,7 +232,7 @@ class TcpResolver : public TcpState
if (fd != _pipe.in() || !(flags & readable)) return this;

// proceed to the next state
return proceed();
return proceed(monitor);
}

/**
Expand All @@ -243,7 +246,7 @@ class TcpResolver : public TcpState
_thread.join();

// proceed to the next state
return proceed();
return proceed(monitor);
}

/**
Expand All @@ -262,4 +265,3 @@ class TcpResolver : public TcpState
* End of namespace
*/
}

0 comments on commit 6827231

Please sign in to comment.