mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-24 17:30:44 +02:00
moved poll into select
This commit is contained in:
@@ -134,15 +134,6 @@ public:
|
|||||||
/// exceptList is zero, select() will return immediately and the
|
/// exceptList is zero, select() will return immediately and the
|
||||||
/// return value will be 0.
|
/// return value will be 0.
|
||||||
|
|
||||||
static int poll(SocketList& readList, SocketList& writeList, SocketList& exceptList, const Poco::Timespan& timeout);
|
|
||||||
/// Provides same functionality as select() call on the platforms
|
|
||||||
/// that have poll() system call available. The advantage of using poll() over
|
|
||||||
/// select() is that the number of socket file descriptors scanned is dynamically
|
|
||||||
/// determined at runtime and is not subject to static maximum limitations like select().
|
|
||||||
///
|
|
||||||
/// For documentation, see
|
|
||||||
/// select(SocketList&, SocketList&, SocketList&, const Poco::Timespan&)
|
|
||||||
|
|
||||||
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
|
||||||
/// call to poll() or select().
|
/// call to poll() or select().
|
||||||
|
|||||||
@@ -91,11 +91,9 @@ Socket::~Socket()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Socket::poll(SocketList& readList, SocketList& writeList, SocketList& exceptList, const Poco::Timespan& timeout)
|
int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exceptList, const Poco::Timespan& timeout)
|
||||||
{
|
{
|
||||||
#if !defined(POCO_HAVE_FD_POLL)
|
#if defined(POCO_HAVE_FD_POLL)
|
||||||
throw NotImplementedException("poll() is only available on POSIX platforms");
|
|
||||||
#else
|
|
||||||
nfds_t nfd = readList.size() + writeList.size() + exceptList.size();
|
nfds_t nfd = readList.size() + writeList.size() + exceptList.size();
|
||||||
if (0 == nfd) return 0;
|
if (0 == nfd) return 0;
|
||||||
|
|
||||||
@@ -173,15 +171,12 @@ int Socket::poll(SocketList& readList, SocketList& writeList, SocketList& except
|
|||||||
}
|
}
|
||||||
std::swap(readList, readyReadList);
|
std::swap(readList, readyReadList);
|
||||||
std::swap(writeList, readyWriteList);
|
std::swap(writeList, readyWriteList);
|
||||||
std::swap(exceptList, readyExceptList);
|
std::swap(exceptList, readyExceptList);
|
||||||
|
|
||||||
|
// return rc;
|
||||||
return readList.size() + writeList.size() + exceptList.size();
|
return readList.size() + writeList.size() + exceptList.size();
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#else
|
||||||
int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exceptList, const Poco::Timespan& timeout)
|
|
||||||
{
|
|
||||||
fd_set fdRead;
|
fd_set fdRead;
|
||||||
fd_set fdWrite;
|
fd_set fdWrite;
|
||||||
fd_set fdExcept;
|
fd_set fdExcept;
|
||||||
@@ -250,8 +245,10 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
|
|||||||
if (FD_ISSET(it->sockfd(), &fdExcept))
|
if (FD_ISSET(it->sockfd(), &fdExcept))
|
||||||
readyExceptList.push_back(*it);
|
readyExceptList.push_back(*it);
|
||||||
}
|
}
|
||||||
std::swap(exceptList, readyExceptList);
|
std::swap(exceptList, readyExceptList);
|
||||||
return rc;
|
|
||||||
|
return rc;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -121,11 +121,7 @@ void SocketReactor::run()
|
|||||||
{
|
{
|
||||||
onIdle();
|
onIdle();
|
||||||
}
|
}
|
||||||
#if defined(POCO_HAVE_FD_POLL)
|
|
||||||
else if (Socket::poll(readable, writable, except, _timeout))
|
|
||||||
#else
|
|
||||||
else if (Socket::select(readable, writable, except, _timeout))
|
else if (Socket::select(readable, writable, except, _timeout))
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
for (Socket::SocketList::iterator it = readable.begin(); it != readable.end(); ++it)
|
for (Socket::SocketList::iterator it = readable.begin(); it != readable.end(); ++it)
|
||||||
dispatch(*it, _pReadableNotification);
|
dispatch(*it, _pReadableNotification);
|
||||||
|
|||||||
Reference in New Issue
Block a user