Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed EventHandlerMap key #3116

Merged
merged 3 commits into from Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Net/include/Poco/Net/SocketReactor.h
Expand Up @@ -209,7 +209,7 @@ class Net_API SocketReactor: public Poco::Runnable
private:
typedef Poco::AutoPtr<SocketNotifier> NotifierPtr;
typedef Poco::AutoPtr<SocketNotification> NotificationPtr;
typedef std::map<Socket, NotifierPtr> EventHandlerMap;
typedef std::map<poco_socket_t, NotifierPtr> EventHandlerMap;
typedef Poco::FastMutex MutexType;
typedef MutexType::ScopedLock ScopedLock;

Expand Down
11 changes: 8 additions & 3 deletions Net/src/SocketReactor.cpp
Expand Up @@ -179,26 +179,31 @@ bool SocketReactor::hasEventHandler(const Socket& socket, const Poco::AbstractOb

SocketReactor::NotifierPtr SocketReactor::getNotifier(const Socket& socket, bool makeNew)
{
const SocketImpl* pImpl = socket.impl();
if (pImpl == nullptr) return 0;
poco_socket_t sockfd = pImpl->sockfd();
ScopedLock lock(_mutex);

EventHandlerMap::iterator it = _handlers.find(socket);
EventHandlerMap::iterator it = _handlers.find(sockfd);
if (it != _handlers.end()) return it->second;
else if (makeNew) return (_handlers[socket] = new SocketNotifier(socket));
else if (makeNew) return (_handlers[sockfd] = new SocketNotifier(socket));

return 0;
}


void SocketReactor::removeEventHandler(const Socket& socket, const Poco::AbstractObserver& observer)
{
const SocketImpl* pImpl = socket.impl();
if (pImpl == nullptr) return;
NotifierPtr pNotifier = getNotifier(socket);
if (pNotifier && pNotifier->hasObserver(observer))
{
if(pNotifier->countObservers() == 1)
{
{
ScopedLock lock(_mutex);
_handlers.erase(socket);
_handlers.erase(pImpl->sockfd());
}
_pollSet.remove(socket);
}
Expand Down