Changed EventHandlerMap key (#3116)

* Changed EventHandlerMap key

Changed EventHandlerMap key from Socket to poco_socket_t to avoid errors in removing/access EventHandlerMap when for example we make an SSL handshake

* Changed EventHandlerMap key

Changed EventHandlerMap key from Socket to poco_socket_t to avoid errors in removing/access EventHandlerMap when for example we make an SSL handshake

* avoid too much call to sockfd() and impl()
This commit is contained in:
micheleselea 2020-10-05 13:47:47 +02:00 committed by GitHub
parent 013c867615
commit dd0dc49b56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -209,7 +209,7 @@ protected:
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;

View File

@ -179,11 +179,14 @@ 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;
}
@ -191,6 +194,8 @@ SocketReactor::NotifierPtr SocketReactor::getNotifier(const Socket& socket, bool
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))
{
@ -198,7 +203,7 @@ void SocketReactor::removeEventHandler(const Socket& socket, const Poco::Abstrac
{
{
ScopedLock lock(_mutex);
_handlers.erase(socket);
_handlers.erase(pImpl->sockfd());
}
_pollSet.remove(socket);
}