add PollSet::has/empty(); ParallelAcceptor: always use same reactor for a socket, if registered

This commit is contained in:
Alex Fabijanic
2018-05-01 13:23:21 -05:00
committed by Alex Fabijanic
parent f6e6bec32d
commit df46368413
8 changed files with 139 additions and 31 deletions

View File

@@ -109,6 +109,20 @@ public:
_socketMap.erase(socket.impl());
}
bool has(const Socket& socket) const
{
Poco::FastMutex::ScopedLock lock(_mutex);
SocketImpl* sockImpl = socket.impl();
return sockImpl &&
(_socketMap.find(sockImpl->sockfd()) != _socketMap.end());
}
bool empty() const
{
Poco::FastMutex::ScopedLock lock(_mutex);
return _socketMap.empty();
}
void update(const Socket& socket, int mode)
{
poco_socket_t fd = socket.impl()->sockfd();
@@ -186,9 +200,9 @@ public:
}
private:
Poco::FastMutex _mutex;
int _epollfd;
std::map<void*, Socket> _socketMap;
mutable Poco::FastMutex _mutex;
int _epollfd;
std::map<void*, Socket> _socketMap;
std::vector<struct epoll_event> _events;
};
@@ -222,6 +236,20 @@ public:
_socketMap.erase(fd);
}
bool has(const Socket& socket) const
{
Poco::FastMutex::ScopedLock lock(_mutex);
SocketImpl* sockImpl = socket.impl();
return sockImpl &&
(_socketMap.find(sockImpl->sockfd()) != _socketMap.end());
}
bool empty() const
{
Poco::FastMutex::ScopedLock lock(_mutex);
return _socketMap.empty();
}
void update(const Socket& socket, int mode)
{
Poco::FastMutex::ScopedLock lock(_mutex);
@@ -337,11 +365,11 @@ public:
}
private:
Poco::FastMutex _mutex;
mutable Poco::FastMutex _mutex;
std::map<poco_socket_t, Socket> _socketMap;
std::map<poco_socket_t, int> _addMap;
std::set<poco_socket_t> _removeSet;
std::vector<pollfd> _pollfds;
std::map<poco_socket_t, int> _addMap;
std::set<poco_socket_t> _removeSet;
std::vector<pollfd> _pollfds;
};
@@ -357,28 +385,36 @@ public:
void add(const Socket& socket, int mode)
{
Poco::FastMutex::ScopedLock lock(_mutex);
_map[socket] = mode;
}
void remove(const Socket& socket)
{
Poco::FastMutex::ScopedLock lock(_mutex);
_map.erase(socket);
}
bool has(const Socket& socket) const
{
Poco::FastMutex::ScopedLock lock(_mutex);
return _map.find(socket) != _map.end();
}
bool empty() const
{
Poco::FastMutex::ScopedLock lock(_mutex);
return _map.empty();
}
void update(const Socket& socket, int mode)
{
Poco::FastMutex::ScopedLock lock(_mutex);
_map[socket] = mode;
}
void clear()
{
Poco::FastMutex::ScopedLock lock(_mutex);
_map.clear();
}
@@ -472,8 +508,8 @@ public:
}
private:
Poco::FastMutex _mutex;
PollSet::SocketModeMap _map;
mutable Poco::FastMutex _mutex;
PollSet::SocketModeMap _map;
};
@@ -510,6 +546,18 @@ void PollSet::update(const Socket& socket, int mode)
}
bool PollSet::has(const Socket& socket) const
{
return _pImpl->has(socket);
}
bool PollSet::empty() const
{
return _pImpl->empty();
}
void PollSet::clear()
{
_pImpl->clear();