Skip to content

Commit

Permalink
enh(Net): add PollSet::size(); mark PollSet::count() as deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
obiltschnig committed Nov 17, 2024
1 parent c386bba commit 2815ea4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
12 changes: 9 additions & 3 deletions Net/include/Poco/Net/PollSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ class Net_API PollSet
bool empty() const;
/// Returns true if no socket is registered for polling.

std::size_t size() const;
/// Returns the number of sockets monitored.

//@ deprecated
int count() const;
/// Returns the number of sockets monitored.
/// This method is deprecated. Use size() instead.

void clear();
/// Removes all sockets from the PollSet.

Expand All @@ -102,14 +110,12 @@ class Net_API PollSet
/// Returns a PollMap containing the sockets that have had
/// their state changed.

int count() const;
/// Returns the number of sockets monitored.

void wakeUp();
/// Wakes up a waiting PollSet.
/// Any errors that occur during this call are ignored.
/// On platforms/implementations where this functionality
/// is not available, it does nothing.

private:
PollSetImpl* _pImpl;

Expand Down
24 changes: 15 additions & 9 deletions Net/src/PollSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class PollSetImpl
while (true)
{
Poco::Timestamp start;
rc = epoll_wait(_epollfd, &_events[0], static_cast<int>(_events.size()), static_cast<int>(remainingTime.totalMilliseconds()));
rc = epoll_wait(_epollfd, _events.data(), static_cast<int>(_events.size()), static_cast<int>(remainingTime.totalMilliseconds()));
if (rc == 0)
{
if (keepWaiting(start, remainingTime)) continue;
Expand Down Expand Up @@ -242,10 +242,10 @@ class PollSetImpl
#endif
}

int count() const
std::size_t size() const
{
ScopedLock lock(_mutex);
return static_cast<int>(_socketMap.size());
return _socketMap.size();
}

private:
Expand Down Expand Up @@ -454,7 +454,7 @@ class PollSetImpl
do
{
Poco::Timestamp start;
rc = ::poll(&_pollfds[0], _pollfds.size(), remainingTime.totalMilliseconds());
rc = ::poll(_pollfds.data(), _pollfds.size(), remainingTime.totalMilliseconds());
if (rc < 0 && SocketImpl::lastError() == POCO_EINTR)
{
Poco::Timestamp end;
Expand Down Expand Up @@ -505,10 +505,10 @@ class PollSetImpl
_pipe.writeBytes(&c, 1);
}

int count() const
std::size_t size() const
{
Poco::FastMutex::ScopedLock lock(_mutex);
return static_cast<int>(_socketMap.size());
return _socketMap.size();
}

private:
Expand Down Expand Up @@ -669,10 +669,10 @@ class PollSetImpl
// TODO
}

int count() const
std::size_t size() const
{
Poco::FastMutex::ScopedLock lock(_mutex);
return static_cast<int>(_map.size());
return _map.size();
}

private:
Expand Down Expand Up @@ -740,7 +740,13 @@ PollSet::SocketModeMap PollSet::poll(const Poco::Timespan& timeout)

int PollSet::count() const
{
return _pImpl->count();
return static_cast<int>(_pImpl->size());
}


std::size_t PollSet::size() const
{
return _pImpl->size();
}


Expand Down

0 comments on commit 2815ea4

Please sign in to comment.