mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 18:42:41 +01:00
poll() support (tested on Solaris and Linux)
array delete policy for SharedPtr
This commit is contained in:
@@ -40,6 +40,9 @@
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
#include <string.h> // FD_SET needs memset on some platforms, so we can't use <cstring>
|
||||
#if defined(POCO_HAVE_FD_POLL)
|
||||
#include <poll.h>
|
||||
#endif
|
||||
|
||||
|
||||
using Poco::IOException;
|
||||
@@ -335,9 +338,37 @@ int SocketImpl::available()
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
|
||||
{
|
||||
#if defined(POCO_HAVE_FD_POLL)
|
||||
|
||||
pollfd pollBuf;
|
||||
|
||||
std::memset(&pollBuf, 0, sizeof(pollfd));
|
||||
pollBuf.fd = _sockfd;
|
||||
if (mode & SELECT_READ) pollBuf.events |= POLLIN;
|
||||
if (mode & SELECT_WRITE) pollBuf.events |= POLLOUT;
|
||||
|
||||
Poco::Timespan remainingTime(timeout);
|
||||
int rc;
|
||||
do
|
||||
{
|
||||
Poco::Timestamp start;
|
||||
rc = ::poll(&pollBuf, 1, remainingTime.totalMilliseconds());
|
||||
|
||||
if (rc < 0 && lastError() == POCO_EINTR)
|
||||
{
|
||||
Poco::Timestamp end;
|
||||
Poco::Timespan waited = end - start;
|
||||
if (waited < remainingTime)
|
||||
remainingTime -= waited;
|
||||
else
|
||||
remainingTime = 0;
|
||||
}
|
||||
} while (rc < 0 && lastError() == POCO_EINTR);
|
||||
|
||||
#else
|
||||
|
||||
fd_set fdRead;
|
||||
fd_set fdWrite;
|
||||
fd_set fdExcept;
|
||||
@@ -376,6 +407,9 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
|
||||
}
|
||||
}
|
||||
while (rc < 0 && lastError() == POCO_EINTR);
|
||||
|
||||
#endif
|
||||
|
||||
if (rc < 0) error();
|
||||
return rc > 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user