- remove kqueue support from Socket::select and SocketImpl::poll.

This code does not work well, I am sorry.
This commit is contained in:
Sergey N. Yatskevich 2010-04-01 11:30:30 +00:00
parent 99242a4862
commit bf87d53ac7
3 changed files with 0 additions and 159 deletions

View File

@ -189,11 +189,6 @@
#define POCO_HAVE_FD_EPOLL 1
#endif
//TODO: need to determine which of FreeBSD have kqueue
#if (POCO_OS == POCO_OS_FREE_BSD)
#define POCO_HAVE_FD_KQUEUE 1
#endif
//TODO: determine all platforms having poll() call
#if (POCO_OS == POCO_OS_SOLARIS) || (POCO_OS == POCO_OS_LINUX)
#define POCO_HAVE_FD_POLL 1

View File

@ -43,10 +43,6 @@
#if defined(POCO_HAVE_FD_EPOLL)
#include <sys/epoll.h>
#elif defined(POCO_HAVE_FD_KQUEUE)
#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
#elif defined(POCO_HAVE_FD_POLL)
#include "Poco/SharedPtr.h"
#include <poll.h>
@ -247,91 +243,6 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
std::swap(exceptList, readyExceptList);
return readList.size() + writeList.size() + exceptList.size();
#elif defined(POCO_HAVE_FD_KQUEUE)
int kqueue_size = readList.size() + writeList.size() + exceptList.size();
if (kqueue_size == 0) return 0;
int kqueuefd = kqueue();
if (kqueuefd < 0)
{
char buf[4000];
strerror_r(errno, buf, sizeof(buf));
SocketImpl::error(std::string("Can't create kqueue - ") + buf);
}
struct kevent events_in[kqueue_size];
struct kevent events_out[kqueue_size];
memset(&events_in , 0, sizeof(events_in));
memset(&events_out, 0, sizeof(events_out));
for (size_t i = 0; i < readList.size(); ++i)
{
if (readList[i].sockfd () != POCO_INVALID_SOCKET)
{
EV_SET(events_in + i, readList[i].sockfd (), EVFILT_READ, EV_ADD|EV_CLEAR, 0, 0, &readList[i]);
}
}
for (size_t i = 0; i < writeList.size(); ++i)
{
if (writeList[i].sockfd () != POCO_INVALID_SOCKET)
{
EV_SET(events_in + readList.size () + i, writeList[i].sockfd (), EVFILT_WRITE, EV_ADD|EV_CLEAR, 0, 0, &writeList[i]);
}
}
for (size_t i = 0; i < exceptList.size(); ++i)
{
if (exceptList[i].sockfd () != POCO_INVALID_SOCKET)
{
EV_SET(events_in + readList.size () + writeList.size () + i, exceptList[i].sockfd (), EVFILT_READ/*FIXME*/, EV_ADD|EV_CLEAR, 0, 0, &exceptList[i]);
}
}
Poco::Timespan remainingTime(timeout);
int rc;
do
{
struct timespec ts;
ts.tv_sec = (long)remainingTime.totalSeconds();
ts.tv_nsec = (long)remainingTime.useconds();
Poco::Timestamp start;
rc = kevent(kqueuefd, events_in, kqueue_size, events_out, kqueue_size, &ts);
if (rc < 0 && SocketImpl::lastError() == POCO_EINTR)
{
Poco::Timestamp end;
Poco::Timespan waited = end - start;
if (waited < remainingTime)
remainingTime -= waited;
else
remainingTime = 0;
}
}
while (rc < 0 && SocketImpl::lastError() == POCO_EINTR);
::close(kqueuefd);
if (rc < 0) SocketImpl::error();
SocketList readyReadList;
SocketList readyWriteList;
SocketList readyExceptList;
for (int n = 0; n < rc; ++n)
{
if (events_out[n].flags & EV_ERROR)
readyExceptList.push_back(*reinterpret_cast<Socket*>(events_out[n].udata));
else if (events_out[n].filter == EVFILT_READ)
readyReadList.push_back(*reinterpret_cast<Socket*>(events_out[n].udata));
else if (events_out[n].filter == EVFILT_WRITE)
readyWriteList.push_back(*reinterpret_cast<Socket*>(events_out[n].udata));
}
std::swap(readList, readyReadList);
std::swap(writeList, readyWriteList);
std::swap(exceptList, readyExceptList);
return readList.size() + writeList.size() + exceptList.size();
#elif defined(POCO_HAVE_FD_POLL)
nfds_t nfd = readList.size() + writeList.size() + exceptList.size();

View File

@ -44,10 +44,6 @@
#if defined(POCO_HAVE_FD_EPOLL)
#include <sys/epoll.h>
#elif defined(POCO_HAVE_FD_KQUEUE)
#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
#elif defined(POCO_HAVE_FD_POLL)
#include <poll.h>
#endif
@ -415,67 +411,6 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
if (rc < 0) error();
return rc > 0;
#elif defined(POCO_HAVE_FD_KQUEUE)
int kqueuefd = kqueue();
if (kqueuefd < 0)
{
char buf[4000];
strerror_r(errno, buf, sizeof(buf));
error(std::string("Can't create kqueue - ") + buf);
}
struct kevent events_in[3];
memset(events_in, 0, sizeof(events_in));
int kqueue_size = 0;
if (mode & SELECT_READ)
{
EV_SET(&events_in[kqueue_size], _sockfd, EVFILT_READ, EV_ADD|EV_CLEAR, 0, 0, &events_in[kqueue_size]);
++kqueue_size;
}
if (mode & SELECT_WRITE)
{
EV_SET(&events_in[kqueue_size], _sockfd, EVFILT_WRITE, EV_ADD|EV_CLEAR, 0, 0, &events_in[kqueue_size]);
++kqueue_size;
}
if (mode & SELECT_ERROR)
{
EV_SET(&events_in[kqueue_size], _sockfd, EVFILT_READ/*FIXME:*/, EV_ADD|EV_CLEAR, 0, 0, &events_in[kqueue_size]);
++kqueue_size;
}
Poco::Timespan remainingTime(timeout);
int rc;
do
{
struct kevent events_out[kqueue_size];
memset(events_out, 0, sizeof(events_out));
struct timespec ts;
ts.tv_sec = (long)remainingTime.totalSeconds();
ts.tv_nsec = (long)remainingTime.useconds();
Poco::Timestamp start;
rc = kevent(kqueuefd, events_in, kqueue_size, events_out, kqueue_size, &ts);
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);
::close(kqueuefd);
if (rc < 0) error();
return rc > 0;
#elif defined(POCO_HAVE_FD_POLL)
pollfd pollBuf;