Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make poll set interruptable #3644

Merged
merged 5 commits into from
Jun 28, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 18 additions & 3 deletions Net/src/PollSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#elif defined(POCO_HAVE_FD_POLL)
#ifndef _WIN32
#include <poll.h>
#include "Poco/Pipe.h"
#endif
#endif

Expand Down Expand Up @@ -226,6 +227,17 @@ class PollSetImpl
class PollSetImpl
{
public:
PollSetImpl()
{
JackyWoo marked this conversation as resolved.
Show resolved Hide resolved
pollfd fd{_pipe.readHandle(), POLLIN, 0};
_pollfds[0] = fd;
}

~PollSetImpl()
{
_pipe.close();
}

void add(const Socket& socket, int mode)
{
Poco::FastMutex::ScopedLock lock(_mutex);
Expand Down Expand Up @@ -280,7 +292,7 @@ class PollSetImpl
_socketMap.clear();
_addMap.clear();
_removeSet.clear();
_pollfds.clear();
_pollfds.reserve(1);
}

PollSet::SocketModeMap poll(const Poco::Timespan& timeout)
Expand Down Expand Up @@ -345,7 +357,7 @@ class PollSetImpl

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())
Expand All @@ -371,7 +383,8 @@ class PollSetImpl

void wakeUp()
{
// TODO
char c = 1;
_pipe.writeBytes(&c, 1);
}

int count() const
Expand All @@ -396,6 +409,8 @@ class PollSetImpl
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
};


Expand Down