-removed #warning (not portable)

- modified appinf IP address
This commit is contained in:
Aleksandar Fabijanic 2010-03-31 12:26:52 +00:00
parent acba77b3ce
commit 99242a4862
3 changed files with 12 additions and 99 deletions

View File

@ -103,41 +103,22 @@ Socket::~Socket()
int Socket::select(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_EPOLL) #if defined(POCO_HAVE_FD_EPOLL)
#warning "Poco use EPOLL for Socket::select"
//
// Size of epoll queue
//
int epoll_size = readList.size() + writeList.size() + exceptList.size(); int epoll_size = readList.size() + writeList.size() + exceptList.size();
// if (epoll_size == 0) return 0;
// If nothing to do, return 0
//
if (epoll_size == 0)
return 0;
//
// Fill epoll queue
//
int epollfd = -1; int epollfd = -1;
{ {
//
// Epoll events to be filled
//
struct epoll_event events_in[epoll_size]; struct epoll_event events_in[epoll_size];
memset(events_in, 0, sizeof (events_in)); memset(events_in, 0, sizeof (events_in));
//
// Current epoll event to be filled
//
struct epoll_event* event_last = events_in; struct epoll_event* event_last = events_in;
for (SocketList::iterator it = readList.begin(); it != readList.end(); ++it) for (SocketList::iterator it = readList.begin(); it != readList.end(); ++it)
{ {
if (it->sockfd() != POCO_INVALID_SOCKET) if (it->sockfd() != POCO_INVALID_SOCKET)
{ {
//
// Try to find file descriptor in epoll events
//
struct epoll_event* e = events_in; struct epoll_event* e = events_in;
for (; e != event_last; ++e) for (; e != event_last; ++e)
{ {
@ -145,9 +126,6 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
break; break;
} }
//
// If not found allocate new epoll event
//
if (e == event_last) if (e == event_last)
{ {
e->data.ptr = &(*it); e->data.ptr = &(*it);
@ -163,9 +141,6 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
{ {
if (it->sockfd() != POCO_INVALID_SOCKET) if (it->sockfd() != POCO_INVALID_SOCKET)
{ {
//
// Try to find file descriptor in epoll events
//
struct epoll_event* e = events_in; struct epoll_event* e = events_in;
for (; e != event_last; ++e) for (; e != event_last; ++e)
{ {
@ -173,9 +148,6 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
break; break;
} }
//
// If not found allocate new epoll event
//
if (e == event_last) if (e == event_last)
{ {
e->data.ptr = &(*it); e->data.ptr = &(*it);
@ -191,9 +163,6 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
{ {
if (it->sockfd() != POCO_INVALID_SOCKET) if (it->sockfd() != POCO_INVALID_SOCKET)
{ {
//
// Try to find file descriptor in epoll events
//
struct epoll_event* e = events_in; struct epoll_event* e = events_in;
for (; e != event_last; ++e) for (; e != event_last; ++e)
{ {
@ -201,9 +170,6 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
break; break;
} }
//
// If not found allocate new epoll event
//
if (e == event_last) if (e == event_last)
{ {
e->data.ptr = &(*it); e->data.ptr = &(*it);
@ -215,14 +181,8 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
} }
} }
//
// Recalculate real epoll queue size
//
epoll_size = event_last - events_in; epoll_size = event_last - events_in;
//
// Allocate epoll queue
//
epollfd = epoll_create(epoll_size); epollfd = epoll_create(epoll_size);
if (epollfd < 0) if (epollfd < 0)
{ {
@ -232,9 +192,6 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
SocketImpl::error(std::string("Can't create epoll - ") + buf); SocketImpl::error(std::string("Can't create epoll - ") + buf);
} }
//
// Place epoll events into epoll queue
//
for (struct epoll_event* e = events_in; e != event_last; ++e) for (struct epoll_event* e = events_in; e != event_last; ++e)
{ {
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, reinterpret_cast<Socket*> (e->data.ptr)->sockfd(), e) < 0) if (epoll_ctl(epollfd, EPOLL_CTL_ADD, reinterpret_cast<Socket*> (e->data.ptr)->sockfd(), e) < 0)
@ -269,9 +226,6 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
} }
while (rc < 0 && SocketImpl::lastError() == POCO_EINTR); while (rc < 0 && SocketImpl::lastError() == POCO_EINTR);
//
// Close epoll queue
//
::close(epollfd); ::close(epollfd);
if (rc < 0) SocketImpl::error(); if (rc < 0) SocketImpl::error();
@ -294,21 +248,11 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
return readList.size() + writeList.size() + exceptList.size(); return readList.size() + writeList.size() + exceptList.size();
#elif defined(POCO_HAVE_FD_KQUEUE) #elif defined(POCO_HAVE_FD_KQUEUE)
#warning "Poco use KQUEUE for Socket::select"
//
// Size of kqueue queue
//
int kqueue_size = readList.size() + writeList.size() + exceptList.size(); int kqueue_size = readList.size() + writeList.size() + exceptList.size();
// if (kqueue_size == 0) return 0;
// If nothing to do, return 0
//
if (kqueue_size == 0)
return 0;
//
// Create kevent queue
//
int kqueuefd = kqueue(); int kqueuefd = kqueue();
if (kqueuefd < 0) if (kqueuefd < 0)
{ {
@ -318,17 +262,11 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
SocketImpl::error(std::string("Can't create kqueue - ") + buf); SocketImpl::error(std::string("Can't create kqueue - ") + buf);
} }
//
// Allocate in/out kevent queues
//
struct kevent events_in[kqueue_size]; struct kevent events_in[kqueue_size];
struct kevent events_out[kqueue_size]; struct kevent events_out[kqueue_size];
memset(&events_in , 0, sizeof(events_in)); memset(&events_in , 0, sizeof(events_in));
memset(&events_out, 0, sizeof(events_out)); memset(&events_out, 0, sizeof(events_out));
//
// Add sockets to events_in list for appropriate event
//
for (size_t i = 0; i < readList.size(); ++i) for (size_t i = 0; i < readList.size(); ++i)
{ {
if (readList[i].sockfd () != POCO_INVALID_SOCKET) if (readList[i].sockfd () != POCO_INVALID_SOCKET)
@ -373,9 +311,6 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
} }
while (rc < 0 && SocketImpl::lastError() == POCO_EINTR); while (rc < 0 && SocketImpl::lastError() == POCO_EINTR);
//
// Close kqueue
//
::close(kqueuefd); ::close(kqueuefd);
if (rc < 0) SocketImpl::error(); if (rc < 0) SocketImpl::error();
@ -398,7 +333,7 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
return readList.size() + writeList.size() + exceptList.size(); return readList.size() + writeList.size() + exceptList.size();
#elif defined(POCO_HAVE_FD_POLL) #elif defined(POCO_HAVE_FD_POLL)
#warning "Poco use POLL for Socket::select"
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;
@ -478,11 +413,10 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
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();
#else #else
#warning "Poco use SELECT for Socket::select"
fd_set fdRead; fd_set fdRead;
fd_set fdWrite; fd_set fdWrite;
fd_set fdExcept; fd_set fdExcept;

View File

@ -360,10 +360,7 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
poco_assert (_sockfd != POCO_INVALID_SOCKET); poco_assert (_sockfd != POCO_INVALID_SOCKET);
#if defined(POCO_HAVE_FD_EPOLL) #if defined(POCO_HAVE_FD_EPOLL)
#warning "Poco use EPOLL for SocketImpl::poll"
//
// Allocate epoll queue
//
int epollfd = epoll_create(1); int epollfd = epoll_create(1);
if (epollfd < 0) if (epollfd < 0)
{ {
@ -373,9 +370,6 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
error(std::string("Can't create epoll - ") + buf); error(std::string("Can't create epoll - ") + buf);
} }
//
// Fill epoll event
//
struct epoll_event ev_in; struct epoll_event ev_in;
memset(&ev_in, 0, sizeof(ev_in)); memset(&ev_in, 0, sizeof(ev_in));
@ -386,9 +380,6 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
if (mode & SELECT_ERROR) if (mode & SELECT_ERROR)
ev_in.events |= EPOLLERR; ev_in.events |= EPOLLERR;
//
// Add epoll event to epoll queue
//
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, _sockfd, &ev_in) < 0) if (epoll_ctl(epollfd, EPOLL_CTL_ADD, _sockfd, &ev_in) < 0)
{ {
char buf[4000]; char buf[4000];
@ -419,19 +410,13 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
} }
while (rc < 0 && lastError() == POCO_EINTR); while (rc < 0 && lastError() == POCO_EINTR);
//
// Close epoll
//
::close(epollfd); ::close(epollfd);
if (rc < 0) error(); if (rc < 0) error();
return rc > 0; return rc > 0;
#elif defined(POCO_HAVE_FD_KQUEUE) #elif defined(POCO_HAVE_FD_KQUEUE)
#warning "Poco use KQUEUE for SocketImpl::poll"
//
// Allocate kevent queue
//
int kqueuefd = kqueue(); int kqueuefd = kqueue();
if (kqueuefd < 0) if (kqueuefd < 0)
{ {
@ -441,9 +426,6 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
error(std::string("Can't create kqueue - ") + buf); error(std::string("Can't create kqueue - ") + buf);
} }
//
// Fill kevent queue
//
struct kevent events_in[3]; struct kevent events_in[3];
memset(events_in, 0, sizeof(events_in)); memset(events_in, 0, sizeof(events_in));
@ -489,16 +471,13 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
} }
while (rc < 0 && lastError() == POCO_EINTR); while (rc < 0 && lastError() == POCO_EINTR);
//
// Close kqueue
//
::close(kqueuefd); ::close(kqueuefd);
if (rc < 0) error(); if (rc < 0) error();
return rc > 0; return rc > 0;
#elif defined(POCO_HAVE_FD_POLL) #elif defined(POCO_HAVE_FD_POLL)
#warning "Poco use POLL for SocketImpl::poll"
pollfd pollBuf; pollfd pollBuf;
memset(&pollBuf, 0, sizeof(pollfd)); memset(&pollBuf, 0, sizeof(pollfd));
@ -526,7 +505,7 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
while (rc < 0 && lastError() == POCO_EINTR); while (rc < 0 && lastError() == POCO_EINTR);
#else #else
#warning "Poco use SELECT for SocketImpl::poll"
fd_set fdRead; fd_set fdRead;
fd_set fdWrite; fd_set fdWrite;
fd_set fdExcept; fd_set fdExcept;
@ -565,7 +544,7 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
} }
} }
while (rc < 0 && lastError() == POCO_EINTR); while (rc < 0 && lastError() == POCO_EINTR);
#endif // POCO_HAVE_FD_POLL #endif
if (rc < 0) error(); if (rc < 0) error();
return rc > 0; return rc > 0;
} }

View File

@ -84,7 +84,7 @@ void SocketAddressTest::testSocketAddress()
} }
SocketAddress sa4("www.appinf.com", 80); SocketAddress sa4("www.appinf.com", 80);
assert (sa4.host().toString() == "213.229.60.82"); assert (sa4.host().toString() == "216.146.46.35");
assert (sa4.port() == 80); assert (sa4.port() == 80);
try try