Make poll set interruptable (#3644)

* Make poll set interruptable

* open test for poll set

* fix poll set wake up test

* fix build error
This commit is contained in:
JackyWoo
2022-06-29 03:23:10 +08:00
committed by GitHub
parent cc14bcf5f9
commit 0d539a71f5
2 changed files with 26 additions and 5 deletions

View File

@@ -24,6 +24,7 @@
#elif defined(POCO_HAVE_FD_POLL)
#ifndef _WIN32
#include <poll.h>
#include "Poco/Pipe.h"
#endif
#endif
@@ -226,6 +227,17 @@ private:
class PollSetImpl
{
public:
PollSetImpl()
{
pollfd fd{_pipe.readHandle(), POLLIN, 0};
_pollfds.push_back(fd);
}
~PollSetImpl()
{
_pipe.close();
}
void add(const Socket& socket, int mode)
{
Poco::FastMutex::ScopedLock lock(_mutex);
@@ -280,7 +292,7 @@ public:
_socketMap.clear();
_addMap.clear();
_removeSet.clear();
_pollfds.clear();
_pollfds.reserve(1);
}
PollSet::SocketModeMap poll(const Poco::Timespan& timeout)
@@ -341,11 +353,17 @@ public:
if (rc < 0) SocketImpl::error();
{
if (_pollfds[0].revents & POLLIN)
{
char c;
_pipe.readBytes(&c, 1);
}
Poco::FastMutex::ScopedLock lock(_mutex);
if (!_socketMap.empty())
{
for (auto it = _pollfds.begin(); it != _pollfds.end(); ++it)
for (auto it = _pollfds.begin() + 1; it != _pollfds.end(); ++it)
{
std::map<poco_socket_t, Socket>::const_iterator its = _socketMap.find(it->fd);
if (its != _socketMap.end())
@@ -371,7 +389,8 @@ public:
void wakeUp()
{
// TODO
char c = 1;
_pipe.writeBytes(&c, 1);
}
int count() const
@@ -396,6 +415,8 @@ private:
std::map<poco_socket_t, int> _addMap;
std::set<poco_socket_t> _removeSet;
std::vector<pollfd> _pollfds;
Poco::Pipe _pipe;
/// Add _pipe to head of _pollfds used to wake up poll blocking
};