mirror of
https://github.com/pocoproject/poco.git
synced 2025-02-21 06:37:42 +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:
parent
013c867615
commit
dd0dc49b56
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user