mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-28 19:51:58 +01:00
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:
@@ -209,7 +209,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
typedef Poco::AutoPtr<SocketNotifier> NotifierPtr;
|
typedef Poco::AutoPtr<SocketNotifier> NotifierPtr;
|
||||||
typedef Poco::AutoPtr<SocketNotification> NotificationPtr;
|
typedef Poco::AutoPtr<SocketNotification> NotificationPtr;
|
||||||
typedef std::map<Socket, NotifierPtr> EventHandlerMap;
|
typedef std::map<poco_socket_t, NotifierPtr> EventHandlerMap;
|
||||||
typedef Poco::FastMutex MutexType;
|
typedef Poco::FastMutex MutexType;
|
||||||
typedef MutexType::ScopedLock ScopedLock;
|
typedef MutexType::ScopedLock ScopedLock;
|
||||||
|
|
||||||
|
|||||||
@@ -179,11 +179,14 @@ bool SocketReactor::hasEventHandler(const Socket& socket, const Poco::AbstractOb
|
|||||||
|
|
||||||
SocketReactor::NotifierPtr SocketReactor::getNotifier(const Socket& socket, bool makeNew)
|
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);
|
ScopedLock lock(_mutex);
|
||||||
|
|
||||||
EventHandlerMap::iterator it = _handlers.find(socket);
|
EventHandlerMap::iterator it = _handlers.find(sockfd);
|
||||||
if (it != _handlers.end()) return it->second;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -191,6 +194,8 @@ SocketReactor::NotifierPtr SocketReactor::getNotifier(const Socket& socket, bool
|
|||||||
|
|
||||||
void SocketReactor::removeEventHandler(const Socket& socket, const Poco::AbstractObserver& observer)
|
void SocketReactor::removeEventHandler(const Socket& socket, const Poco::AbstractObserver& observer)
|
||||||
{
|
{
|
||||||
|
const SocketImpl* pImpl = socket.impl();
|
||||||
|
if (pImpl == nullptr) return;
|
||||||
NotifierPtr pNotifier = getNotifier(socket);
|
NotifierPtr pNotifier = getNotifier(socket);
|
||||||
if (pNotifier && pNotifier->hasObserver(observer))
|
if (pNotifier && pNotifier->hasObserver(observer))
|
||||||
{
|
{
|
||||||
@@ -198,7 +203,7 @@ void SocketReactor::removeEventHandler(const Socket& socket, const Poco::Abstrac
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
ScopedLock lock(_mutex);
|
ScopedLock lock(_mutex);
|
||||||
_handlers.erase(socket);
|
_handlers.erase(pImpl->sockfd());
|
||||||
}
|
}
|
||||||
_pollSet.remove(socket);
|
_pollSet.remove(socket);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user