mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-18 00:15:27 +01:00
-removed #warning (not portable)
- modified appinf IP address
This commit is contained in:
parent
acba77b3ce
commit
99242a4862
@ -103,41 +103,22 @@ Socket::~Socket()
|
||||
int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exceptList, const Poco::Timespan& timeout)
|
||||
{
|
||||
#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();
|
||||
|
||||
//
|
||||
// If nothing to do, return 0
|
||||
//
|
||||
if (epoll_size == 0)
|
||||
return 0;
|
||||
if (epoll_size == 0) return 0;
|
||||
|
||||
//
|
||||
// Fill epoll queue
|
||||
//
|
||||
int epollfd = -1;
|
||||
{
|
||||
//
|
||||
// Epoll events to be filled
|
||||
//
|
||||
struct epoll_event events_in[epoll_size];
|
||||
memset(events_in, 0, sizeof (events_in));
|
||||
|
||||
//
|
||||
// Current epoll event to be filled
|
||||
//
|
||||
struct epoll_event* event_last = events_in;
|
||||
|
||||
for (SocketList::iterator it = readList.begin(); it != readList.end(); ++it)
|
||||
{
|
||||
if (it->sockfd() != POCO_INVALID_SOCKET)
|
||||
{
|
||||
//
|
||||
// Try to find file descriptor in epoll events
|
||||
//
|
||||
struct epoll_event* e = events_in;
|
||||
for (; e != event_last; ++e)
|
||||
{
|
||||
@ -145,9 +126,6 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// If not found allocate new epoll event
|
||||
//
|
||||
if (e == event_last)
|
||||
{
|
||||
e->data.ptr = &(*it);
|
||||
@ -163,9 +141,6 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
|
||||
{
|
||||
if (it->sockfd() != POCO_INVALID_SOCKET)
|
||||
{
|
||||
//
|
||||
// Try to find file descriptor in epoll events
|
||||
//
|
||||
struct epoll_event* e = events_in;
|
||||
for (; e != event_last; ++e)
|
||||
{
|
||||
@ -173,9 +148,6 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// If not found allocate new epoll event
|
||||
//
|
||||
if (e == event_last)
|
||||
{
|
||||
e->data.ptr = &(*it);
|
||||
@ -191,9 +163,6 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
|
||||
{
|
||||
if (it->sockfd() != POCO_INVALID_SOCKET)
|
||||
{
|
||||
//
|
||||
// Try to find file descriptor in epoll events
|
||||
//
|
||||
struct epoll_event* e = events_in;
|
||||
for (; e != event_last; ++e)
|
||||
{
|
||||
@ -201,9 +170,6 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// If not found allocate new epoll event
|
||||
//
|
||||
if (e == event_last)
|
||||
{
|
||||
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;
|
||||
|
||||
//
|
||||
// Allocate epoll queue
|
||||
//
|
||||
epollfd = epoll_create(epoll_size);
|
||||
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);
|
||||
}
|
||||
|
||||
//
|
||||
// Place epoll events into epoll queue
|
||||
//
|
||||
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)
|
||||
@ -269,9 +226,6 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
|
||||
}
|
||||
while (rc < 0 && SocketImpl::lastError() == POCO_EINTR);
|
||||
|
||||
//
|
||||
// Close epoll queue
|
||||
//
|
||||
::close(epollfd);
|
||||
|
||||
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();
|
||||
|
||||
#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();
|
||||
|
||||
//
|
||||
// If nothing to do, return 0
|
||||
//
|
||||
if (kqueue_size == 0)
|
||||
return 0;
|
||||
if (kqueue_size == 0) return 0;
|
||||
|
||||
//
|
||||
// Create kevent queue
|
||||
//
|
||||
int kqueuefd = kqueue();
|
||||
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);
|
||||
}
|
||||
|
||||
//
|
||||
// Allocate in/out kevent queues
|
||||
//
|
||||
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));
|
||||
|
||||
//
|
||||
// Add sockets to events_in list for appropriate event
|
||||
//
|
||||
for (size_t i = 0; i < readList.size(); ++i)
|
||||
{
|
||||
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);
|
||||
|
||||
//
|
||||
// Close kqueue
|
||||
//
|
||||
::close(kqueuefd);
|
||||
|
||||
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();
|
||||
|
||||
#elif defined(POCO_HAVE_FD_POLL)
|
||||
#warning "Poco use POLL for Socket::select"
|
||||
|
||||
nfds_t nfd = readList.size() + writeList.size() + exceptList.size();
|
||||
if (0 == nfd) return 0;
|
||||
|
||||
@ -478,11 +413,10 @@ int Socket::select(SocketList& readList, SocketList& writeList, SocketList& exce
|
||||
std::swap(writeList, readyWriteList);
|
||||
std::swap(exceptList, readyExceptList);
|
||||
|
||||
// return rc;
|
||||
return readList.size() + writeList.size() + exceptList.size();
|
||||
|
||||
#else
|
||||
#warning "Poco use SELECT for Socket::select"
|
||||
|
||||
fd_set fdRead;
|
||||
fd_set fdWrite;
|
||||
fd_set fdExcept;
|
||||
|
@ -360,10 +360,7 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
|
||||
poco_assert (_sockfd != POCO_INVALID_SOCKET);
|
||||
|
||||
#if defined(POCO_HAVE_FD_EPOLL)
|
||||
#warning "Poco use EPOLL for SocketImpl::poll"
|
||||
//
|
||||
// Allocate epoll queue
|
||||
//
|
||||
|
||||
int epollfd = epoll_create(1);
|
||||
if (epollfd < 0)
|
||||
{
|
||||
@ -373,9 +370,6 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
|
||||
error(std::string("Can't create epoll - ") + buf);
|
||||
}
|
||||
|
||||
//
|
||||
// Fill epoll event
|
||||
//
|
||||
struct epoll_event 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)
|
||||
ev_in.events |= EPOLLERR;
|
||||
|
||||
//
|
||||
// Add epoll event to epoll queue
|
||||
//
|
||||
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, _sockfd, &ev_in) < 0)
|
||||
{
|
||||
char buf[4000];
|
||||
@ -419,19 +410,13 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
|
||||
}
|
||||
while (rc < 0 && lastError() == POCO_EINTR);
|
||||
|
||||
//
|
||||
// Close epoll
|
||||
//
|
||||
::close(epollfd);
|
||||
|
||||
if (rc < 0) error();
|
||||
return rc > 0;
|
||||
|
||||
#elif defined(POCO_HAVE_FD_KQUEUE)
|
||||
#warning "Poco use KQUEUE for SocketImpl::poll"
|
||||
//
|
||||
// Allocate kevent queue
|
||||
//
|
||||
|
||||
int kqueuefd = kqueue();
|
||||
if (kqueuefd < 0)
|
||||
{
|
||||
@ -441,9 +426,6 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
|
||||
error(std::string("Can't create kqueue - ") + buf);
|
||||
}
|
||||
|
||||
//
|
||||
// Fill kevent queue
|
||||
//
|
||||
struct kevent events_in[3];
|
||||
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);
|
||||
|
||||
//
|
||||
// Close kqueue
|
||||
//
|
||||
::close(kqueuefd);
|
||||
|
||||
if (rc < 0) error();
|
||||
return rc > 0;
|
||||
|
||||
#elif defined(POCO_HAVE_FD_POLL)
|
||||
#warning "Poco use POLL for SocketImpl::poll"
|
||||
|
||||
pollfd pollBuf;
|
||||
|
||||
memset(&pollBuf, 0, sizeof(pollfd));
|
||||
@ -526,7 +505,7 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
|
||||
while (rc < 0 && lastError() == POCO_EINTR);
|
||||
|
||||
#else
|
||||
#warning "Poco use SELECT for SocketImpl::poll"
|
||||
|
||||
fd_set fdRead;
|
||||
fd_set fdWrite;
|
||||
fd_set fdExcept;
|
||||
@ -565,7 +544,7 @@ bool SocketImpl::poll(const Poco::Timespan& timeout, int mode)
|
||||
}
|
||||
}
|
||||
while (rc < 0 && lastError() == POCO_EINTR);
|
||||
#endif // POCO_HAVE_FD_POLL
|
||||
#endif
|
||||
if (rc < 0) error();
|
||||
return rc > 0;
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ void SocketAddressTest::testSocketAddress()
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
try
|
||||
|
Loading…
x
Reference in New Issue
Block a user