fix(Socket): Socket::select EPOLL implementation returns socket in exceptList when empty list is given #3655; mark select as deprecated #1459

This commit is contained in:
Alex Fabijanic 2022-07-04 22:38:51 +02:00
parent 672d64bfc5
commit 93e58b4468
2 changed files with 10 additions and 4 deletions

View File

@ -130,6 +130,7 @@ public:
void close(); void close();
/// Closes the socket. /// Closes the socket.
//@deprecated
static int select(SocketList& readList, SocketList& writeList, SocketList& exceptList, const Poco::Timespan& timeout); static int select(SocketList& readList, SocketList& writeList, SocketList& exceptList, const Poco::Timespan& timeout);
/// Determines the status of one or more sockets, /// Determines the status of one or more sockets,
/// using a call to select(). /// using a call to select().
@ -159,6 +160,9 @@ public:
/// the closed socket will not be included in any list. /// the closed socket will not be included in any list.
/// In this case, the return value may be greater than the sum /// In this case, the return value may be greater than the sum
/// of all sockets in all list. /// of all sockets in all list.
///
/// This function is deprecated and may be removed in the future releases,
/// please use PollSet class instead.
bool poll(const Poco::Timespan& timeout, int mode) const; bool poll(const Poco::Timespan& timeout, int mode) const;
/// Determines the status of the socket, using a /// Determines the status of the socket, using a

View File

@ -219,12 +219,14 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
SocketList readyExceptList; SocketList readyExceptList;
for (int n = 0; n < rc; ++n) for (int n = 0; n < rc; ++n)
{ {
if (eventsOut[n].events & EPOLLERR) Socket sock = *reinterpret_cast<Socket*>(eventsOut[n].data.ptr);
readyExceptList.push_back(*reinterpret_cast<Socket*>(eventsOut[n].data.ptr)); if ((eventsOut[n].events & EPOLLERR) &&
(std::end(exceptList) != std::find(exceptList.begin(), exceptList.end(), sock)))
readyExceptList.push_back(sock);
if (eventsOut[n].events & EPOLLIN) if (eventsOut[n].events & EPOLLIN)
readyReadList.push_back(*reinterpret_cast<Socket*>(eventsOut[n].data.ptr)); readyReadList.push_back(sock);
if (eventsOut[n].events & EPOLLOUT) if (eventsOut[n].events & EPOLLOUT)
readyWriteList.push_back(*reinterpret_cast<Socket*>(eventsOut[n].data.ptr)); readyWriteList.push_back(sock);
} }
std::swap(readList, readyReadList); std::swap(readList, readyReadList);
std::swap(writeList, readyWriteList); std::swap(writeList, readyWriteList);