poll() support (tested on Solaris and Linux)

array delete policy for SharedPtr
This commit is contained in:
Aleksandar Fabijanic
2008-12-03 20:38:53 +00:00
parent c617bbe551
commit ab0684a1cd
8 changed files with 229 additions and 10 deletions

View File

@@ -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;
}