summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2014-02-08 22:34:11 +0100
committerAttila Molnar <attilamolnar@hush.com>2014-02-08 22:34:11 +0100
commitaea38a0dd702895b7dfd18efd26a0dcead2279fc (patch)
tree471443cdc87a922131a7cbf14c313d46b946ee5d /src
parentb01820c079a605654d6307f6e57d65b339deef7d (diff)
Update SocketEngine::CurrentSetSize in AddFdRef()/DelFdRef()
Diffstat (limited to 'src')
-rw-r--r--src/socketengine.cpp5
-rw-r--r--src/socketengines/socketengine_epoll.cpp3
-rw-r--r--src/socketengines/socketengine_kqueue.cpp3
-rw-r--r--src/socketengines/socketengine_poll.cpp8
-rw-r--r--src/socketengines/socketengine_ports.cpp3
-rw-r--r--src/socketengines/socketengine_select.cpp4
6 files changed, 7 insertions, 19 deletions
diff --git a/src/socketengine.cpp b/src/socketengine.cpp
index c5f8031b5..35fe5292f 100644
--- a/src/socketengine.cpp
+++ b/src/socketengine.cpp
@@ -39,6 +39,7 @@ SocketEngine::SocketEngine()
TotalEvents = WriteEvents = ReadEvents = ErrorEvents = 0;
lastempty = ServerInstance->Time();
indata = outdata = 0;
+ CurrentSetSize = 0;
}
SocketEngine::~SocketEngine()
@@ -103,6 +104,7 @@ bool SocketEngine::AddFdRef(EventHandler* eh)
while (static_cast<unsigned int>(fd) >= ref.size())
ref.resize(ref.empty() ? 1 : (ref.size() * 2));
ref[fd] = eh;
+ CurrentSetSize++;
return true;
}
@@ -110,7 +112,10 @@ void SocketEngine::DelFdRef(EventHandler *eh)
{
int fd = eh->GetFd();
if (GetRef(fd) == eh)
+ {
ref[fd] = NULL;
+ CurrentSetSize--;
+ }
}
bool SocketEngine::HasFd(int fd)
diff --git a/src/socketengines/socketengine_epoll.cpp b/src/socketengines/socketengine_epoll.cpp
index 9e2f6dc2b..7ee01b2cc 100644
--- a/src/socketengines/socketengine_epoll.cpp
+++ b/src/socketengines/socketengine_epoll.cpp
@@ -53,7 +53,6 @@ public:
EPollEngine::EPollEngine() : events(1)
{
- CurrentSetSize = 0;
int max = ulimit(4, 0);
if (max > 0)
{
@@ -136,7 +135,6 @@ bool EPollEngine::AddFd(EventHandler* eh, int event_mask)
ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "New file descriptor: %d", fd);
SocketEngine::SetEventMask(eh, event_mask);
- CurrentSetSize++;
ResizeDouble(events);
return true;
@@ -180,7 +178,6 @@ void EPollEngine::DelFd(EventHandler* eh)
SocketEngine::DelFdRef(eh);
ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Remove file descriptor: %d", fd);
- CurrentSetSize--;
}
int EPollEngine::DispatchEvents()
diff --git a/src/socketengines/socketengine_kqueue.cpp b/src/socketengines/socketengine_kqueue.cpp
index 8666a84fe..c51789b29 100644
--- a/src/socketengines/socketengine_kqueue.cpp
+++ b/src/socketengines/socketengine_kqueue.cpp
@@ -91,7 +91,6 @@ void KQueueEngine::RecoverFromFork()
std::cout << "ERROR: this is a fatal error, exiting now." << std::endl;
ServerInstance->QuickExit(EXIT_STATUS_SOCKETENGINE);
}
- CurrentSetSize = 0;
}
KQueueEngine::~KQueueEngine()
@@ -125,7 +124,6 @@ bool KQueueEngine::AddFd(EventHandler* eh, int event_mask)
SocketEngine::SetEventMask(eh, event_mask);
OnSetEvent(eh, 0, event_mask);
- CurrentSetSize++;
ResizeDouble(ke_list);
return true;
@@ -159,7 +157,6 @@ void KQueueEngine::DelFd(EventHandler* eh)
}
SocketEngine::DelFdRef(eh);
- CurrentSetSize--;
ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Remove file descriptor: %d", fd);
}
diff --git a/src/socketengines/socketengine_poll.cpp b/src/socketengines/socketengine_poll.cpp
index ca9bfd1ea..46a517c51 100644
--- a/src/socketengines/socketengine_poll.cpp
+++ b/src/socketengines/socketengine_poll.cpp
@@ -64,7 +64,6 @@ public:
PollEngine::PollEngine() : events(1), fd_mappings(1)
{
- CurrentSetSize = 0;
struct rlimit limits;
if (!getrlimit(RLIMIT_NOFILE, &limits))
{
@@ -103,14 +102,14 @@ bool PollEngine::AddFd(EventHandler* eh, int event_mask)
return false;
}
+ unsigned int index = CurrentSetSize;
+
if (!SocketEngine::AddFdRef(eh))
{
ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Attempt to add duplicate fd: %d", fd);
return false;
}
- unsigned int index = CurrentSetSize;
-
while (static_cast<unsigned int>(fd) >= fd_mappings.size())
fd_mappings.resize(fd_mappings.size() * 2, -1);
fd_mappings[fd] = index;
@@ -121,7 +120,6 @@ bool PollEngine::AddFd(EventHandler* eh, int event_mask)
ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "New file descriptor: %d (%d; index %d)", fd, events[index].events, index);
SocketEngine::SetEventMask(eh, event_mask);
- CurrentSetSize++;
return true;
}
@@ -176,8 +174,6 @@ void PollEngine::DelFd(EventHandler* eh)
SocketEngine::DelFdRef(eh);
- CurrentSetSize--;
-
ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Remove file descriptor: %d (index: %d) "
"(Filled gap with: %d (index: %d))", fd, index, last_fd, last_index);
}
diff --git a/src/socketengines/socketengine_ports.cpp b/src/socketengines/socketengine_ports.cpp
index 2783ce4cc..226f59f04 100644
--- a/src/socketengines/socketengine_ports.cpp
+++ b/src/socketengines/socketengine_ports.cpp
@@ -79,7 +79,6 @@ PortsEngine::PortsEngine() : events(1)
std::cout << "ERROR: This is a fatal error, exiting now." << std::endl;
ServerInstance->QuickExit(EXIT_STATUS_SOCKETENGINE);
}
- CurrentSetSize = 0;
}
PortsEngine::~PortsEngine()
@@ -110,7 +109,6 @@ bool PortsEngine::AddFd(EventHandler* eh, int event_mask)
port_associate(EngineHandle, PORT_SOURCE_FD, fd, mask_to_events(event_mask), eh);
ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "New file descriptor: %d", fd);
- CurrentSetSize++;
ResizeDouble(events);
return true;
@@ -130,7 +128,6 @@ void PortsEngine::DelFd(EventHandler* eh)
port_dissociate(EngineHandle, PORT_SOURCE_FD, fd);
- CurrentSetSize--;
SocketEngine::DelFdRef(eh);
ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Remove file descriptor: %d", fd);
diff --git a/src/socketengines/socketengine_select.cpp b/src/socketengines/socketengine_select.cpp
index d47847154..7aaa7aaf7 100644
--- a/src/socketengines/socketengine_select.cpp
+++ b/src/socketengines/socketengine_select.cpp
@@ -46,7 +46,6 @@ public:
SelectEngine::SelectEngine()
{
MAX_DESCRIPTORS = FD_SETSIZE;
- CurrentSetSize = 0;
FD_ZERO(&ReadSet);
FD_ZERO(&WriteSet);
@@ -69,8 +68,6 @@ bool SelectEngine::AddFd(EventHandler* eh, int event_mask)
if (fd > MaxFD)
MaxFD = fd;
- CurrentSetSize++;
-
ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "New file descriptor: %d", fd);
return true;
}
@@ -82,7 +79,6 @@ void SelectEngine::DelFd(EventHandler* eh)
if ((fd < 0) || (fd > GetMaxFds() - 1))
return;
- CurrentSetSize--;
SocketEngine::DelFdRef(eh);
FD_CLR(fd, &ReadSet);