mirror of https://github.com/Icinga/icinga2.git
Avoid updating the file descriptor list for poll() unless we really need to
refs #11014
This commit is contained in:
parent
fa7d0448f9
commit
3c76e70fe2
|
@ -73,26 +73,31 @@ void SocketEvents::ThreadProc(void)
|
||||||
{
|
{
|
||||||
Utility::SetThreadName("SocketIO");
|
Utility::SetThreadName("SocketIO");
|
||||||
|
|
||||||
|
pollfd *pfds = NULL;
|
||||||
|
int pfdcount;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
pollfd *pfds;
|
|
||||||
int pfdcount;
|
|
||||||
|
|
||||||
typedef std::map<SOCKET, SocketEventDescriptor>::value_type SocketDesc;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(l_SocketIOMutex);
|
boost::mutex::scoped_lock lock(l_SocketIOMutex);
|
||||||
|
|
||||||
pfdcount = l_SocketIOSockets.size();
|
if (pfds == NULL) {
|
||||||
pfds = new pollfd[pfdcount];
|
typedef std::map<SOCKET, SocketEventDescriptor>::value_type SocketDesc;
|
||||||
|
|
||||||
int i = 0;
|
pfdcount = l_SocketIOSockets.size();
|
||||||
|
pfds = new pollfd[pfdcount];
|
||||||
|
|
||||||
BOOST_FOREACH(const SocketDesc& desc, l_SocketIOSockets) {
|
int i = 0;
|
||||||
pfds[i].fd = desc.first;
|
|
||||||
pfds[i].events = desc.second.Events;
|
|
||||||
pfds[i].revents = 0;
|
|
||||||
|
|
||||||
i++;
|
BOOST_FOREACH(const SocketDesc& desc, l_SocketIOSockets) {
|
||||||
|
pfds[i].fd = desc.first;
|
||||||
|
pfds[i].events = desc.second.Events;
|
||||||
|
pfds[i].revents = 0;
|
||||||
|
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
l_SocketIOFDChanged = false;
|
||||||
|
l_SocketIOCV.notify_all();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,9 +111,8 @@ void SocketEvents::ThreadProc(void)
|
||||||
boost::mutex::scoped_lock lock(l_SocketIOMutex);
|
boost::mutex::scoped_lock lock(l_SocketIOMutex);
|
||||||
|
|
||||||
if (l_SocketIOFDChanged) {
|
if (l_SocketIOFDChanged) {
|
||||||
l_SocketIOFDChanged = false;
|
|
||||||
l_SocketIOCV.notify_all();
|
|
||||||
delete [] pfds;
|
delete [] pfds;
|
||||||
|
pfds = NULL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,8 +157,6 @@ void SocketEvents::ThreadProc(void)
|
||||||
Log(LogCritical, "SocketEvents", "Exception of unknown type thrown in socket I/O handler.");
|
Log(LogCritical, "SocketEvents", "Exception of unknown type thrown in socket I/O handler.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete [] pfds;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,22 +198,24 @@ SocketEvents::~SocketEvents(void)
|
||||||
|
|
||||||
void SocketEvents::Register(Object *lifesupportObject)
|
void SocketEvents::Register(Object *lifesupportObject)
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(l_SocketIOMutex);
|
{
|
||||||
|
boost::mutex::scoped_lock lock(l_SocketIOMutex);
|
||||||
|
|
||||||
VERIFY(m_FD != INVALID_SOCKET);
|
VERIFY(m_FD != INVALID_SOCKET);
|
||||||
|
|
||||||
SocketEventDescriptor desc;
|
SocketEventDescriptor desc;
|
||||||
desc.Events = 0;
|
desc.Events = 0;
|
||||||
desc.EventInterface = this;
|
desc.EventInterface = this;
|
||||||
desc.LifesupportObject = lifesupportObject;
|
desc.LifesupportObject = lifesupportObject;
|
||||||
|
|
||||||
VERIFY(l_SocketIOSockets.find(m_FD) == l_SocketIOSockets.end());
|
VERIFY(l_SocketIOSockets.find(m_FD) == l_SocketIOSockets.end());
|
||||||
|
|
||||||
l_SocketIOSockets[m_FD] = desc;
|
l_SocketIOSockets[m_FD] = desc;
|
||||||
|
|
||||||
m_Events = true;
|
m_Events = true;
|
||||||
|
}
|
||||||
|
|
||||||
/* There's no need to wake up the I/O thread here. */
|
WakeUpThread(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SocketEvents::Unregister(void)
|
void SocketEvents::Unregister(void)
|
||||||
|
|
Loading…
Reference in New Issue