summaryrefslogtreecommitdiff
path: root/src/socketengines
diff options
context:
space:
mode:
Diffstat (limited to 'src/socketengines')
-rw-r--r--src/socketengines/socketengine_epoll.cpp7
-rw-r--r--src/socketengines/socketengine_iocp.cpp6
-rw-r--r--src/socketengines/socketengine_kqueue.cpp6
-rw-r--r--src/socketengines/socketengine_poll.cpp10
-rw-r--r--src/socketengines/socketengine_ports.cpp6
-rw-r--r--src/socketengines/socketengine_select.cpp15
6 files changed, 23 insertions, 27 deletions
diff --git a/src/socketengines/socketengine_epoll.cpp b/src/socketengines/socketengine_epoll.cpp
index 1be0d7cd2..7fed6f250 100644
--- a/src/socketengines/socketengine_epoll.cpp
+++ b/src/socketengines/socketengine_epoll.cpp
@@ -16,7 +16,7 @@
#include "socketengines/socketengine_epoll.h"
#include <ulimit.h>
-EPollEngine::EPollEngine(InspIRCd* Instance) : SocketEngine(Instance)
+EPollEngine::EPollEngine()
{
MAX_DESCRIPTORS = 0;
// This is not a maximum, just a hint at the eventual number of sockets that may be polled.
@@ -45,7 +45,7 @@ EPollEngine::~EPollEngine()
delete[] events;
}
-bool EPollEngine::AddFd(EventHandler* eh)
+bool EPollEngine::AddFd(EventHandler* eh, bool writeFirst)
{
int fd = eh->GetFd();
if ((fd < 0) || (fd > GetMaxFds() - 1))
@@ -68,7 +68,7 @@ bool EPollEngine::AddFd(EventHandler* eh)
struct epoll_event ev;
memset(&ev,0,sizeof(ev));
- eh->Readable() ? ev.events = EPOLLIN : ev.events = EPOLLOUT;
+ ev.events = writeFirst ? EPOLLOUT : EPOLLIN;
ev.data.fd = fd;
int i = epoll_ctl(EngineHandle, EPOLL_CTL_ADD, fd, &ev);
if (i < 0)
@@ -107,7 +107,6 @@ bool EPollEngine::DelFd(EventHandler* eh, bool force)
struct epoll_event ev;
memset(&ev,0,sizeof(ev));
- eh->Readable() ? ev.events = EPOLLIN : ev.events = EPOLLOUT;
ev.data.fd = fd;
int i = epoll_ctl(EngineHandle, EPOLL_CTL_DEL, fd, &ev);
diff --git a/src/socketengines/socketengine_iocp.cpp b/src/socketengines/socketengine_iocp.cpp
index ee2e5afa1..3c3181909 100644
--- a/src/socketengines/socketengine_iocp.cpp
+++ b/src/socketengines/socketengine_iocp.cpp
@@ -15,7 +15,7 @@
#include "exitcodes.h"
#include <mswsock.h>
-IOCPEngine::IOCPEngine(InspIRCd * Instance) : SocketEngine(Instance)
+IOCPEngine::IOCPEngine()
{
MAX_DESCRIPTORS = 10240;
@@ -47,7 +47,7 @@ IOCPEngine::~IOCPEngine()
delete[] ref;
}
-bool IOCPEngine::AddFd(EventHandler* eh)
+bool IOCPEngine::AddFd(EventHandler* eh, bool writeFirst)
{
/* Does it at least look valid? */
if (!eh)
@@ -92,7 +92,7 @@ bool IOCPEngine::AddFd(EventHandler* eh)
ServerInstance->Logs->Log("SOCKET",DEBUG, "New fake fd: %u, real fd: %u, address 0x%p", *fake_fd, eh->GetFd(), eh);
/* post a write event if there is data to be written */
- if(eh->Writeable())
+ if(writeFirst)
WantWrite(eh);
/* we're all good =) */
diff --git a/src/socketengines/socketengine_kqueue.cpp b/src/socketengines/socketengine_kqueue.cpp
index bf09eaf74..cbe3e959d 100644
--- a/src/socketengines/socketengine_kqueue.cpp
+++ b/src/socketengines/socketengine_kqueue.cpp
@@ -19,7 +19,7 @@
#include "socketengines/socketengine_kqueue.h"
#include <sys/sysctl.h>
-KQueueEngine::KQueueEngine(InspIRCd* Instance) : SocketEngine(Instance)
+KQueueEngine::KQueueEngine()
{
MAX_DESCRIPTORS = 0;
this->RecoverFromFork();
@@ -54,7 +54,7 @@ KQueueEngine::~KQueueEngine()
delete[] ke_list;
}
-bool KQueueEngine::AddFd(EventHandler* eh)
+bool KQueueEngine::AddFd(EventHandler* eh, bool writeFirst)
{
int fd = eh->GetFd();
@@ -79,7 +79,7 @@ bool KQueueEngine::AddFd(EventHandler* eh)
return false;
}
- if (!eh->Readable()) {
+ if (writeFirst) {
// ...and sometimes want to write
WantWrite(eh);
}
diff --git a/src/socketengines/socketengine_poll.cpp b/src/socketengines/socketengine_poll.cpp
index cee6a90cb..6d5ddb9f5 100644
--- a/src/socketengines/socketengine_poll.cpp
+++ b/src/socketengines/socketengine_poll.cpp
@@ -19,7 +19,7 @@
#include <sys/sysctl.h>
#endif
-PollEngine::PollEngine(InspIRCd* Instance) : SocketEngine(Instance)
+PollEngine::PollEngine()
{
// Poll requires no special setup (which is nice).
CurrentSetSize = 0;
@@ -39,7 +39,7 @@ PollEngine::~PollEngine()
delete[] events;
}
-bool PollEngine::AddFd(EventHandler* eh)
+bool PollEngine::AddFd(EventHandler* eh, bool writeFirst)
{
int fd = eh->GetFd();
if ((fd < 0) || (fd > GetMaxFds() - 1))
@@ -65,13 +65,13 @@ bool PollEngine::AddFd(EventHandler* eh)
fd_mappings[fd] = index;
ref[index] = eh;
events[index].fd = fd;
- if (eh->Readable())
+ if (writeFirst)
{
- events[index].events = POLLIN;
+ events[index].events = POLLOUT;
}
else
{
- events[index].events = POLLOUT;
+ events[index].events = POLLIN;
}
ServerInstance->Logs->Log("SOCKET", DEBUG,"New file descriptor: %d (%d; index %d)", fd, events[fd].events, index);
diff --git a/src/socketengines/socketengine_ports.cpp b/src/socketengines/socketengine_ports.cpp
index 5efa545b0..eb08839d0 100644
--- a/src/socketengines/socketengine_ports.cpp
+++ b/src/socketengines/socketengine_ports.cpp
@@ -17,7 +17,7 @@
#include "socketengines/socketengine_ports.h"
#include <ulimit.h>
-PortsEngine::PortsEngine(InspIRCd* Instance) : SocketEngine(Instance)
+PortsEngine::PortsEngine()
{
MAX_DESCRIPTORS = 0;
EngineHandle = port_create();
@@ -44,7 +44,7 @@ PortsEngine::~PortsEngine()
delete[] events;
}
-bool PortsEngine::AddFd(EventHandler* eh)
+bool PortsEngine::AddFd(EventHandler* eh, bool writeFirst)
{
int fd = eh->GetFd();
if ((fd < 0) || (fd > GetMaxFds() - 1))
@@ -57,7 +57,7 @@ bool PortsEngine::AddFd(EventHandler* eh)
return false;
ref[fd] = eh;
- port_associate(EngineHandle, PORT_SOURCE_FD, fd, eh->Readable() ? POLLRDNORM : POLLWRNORM, eh);
+ port_associate(EngineHandle, PORT_SOURCE_FD, fd, writeFirst ? POLLWRNORM : POLLRDNORM, eh);
ServerInstance->Logs->Log("SOCKET",DEBUG,"New file descriptor: %d", fd);
CurrentSetSize++;
diff --git a/src/socketengines/socketengine_select.cpp b/src/socketengines/socketengine_select.cpp
index 8c41df11b..7f6a4e283 100644
--- a/src/socketengines/socketengine_select.cpp
+++ b/src/socketengines/socketengine_select.cpp
@@ -18,7 +18,7 @@
#include "socketengines/socketengine_select.h"
-SelectEngine::SelectEngine(InspIRCd* Instance) : SocketEngine(Instance)
+SelectEngine::SelectEngine()
{
MAX_DESCRIPTORS = FD_SETSIZE;
EngineHandle = 0;
@@ -34,7 +34,7 @@ SelectEngine::~SelectEngine()
delete[] ref;
}
-bool SelectEngine::AddFd(EventHandler* eh)
+bool SelectEngine::AddFd(EventHandler* eh, bool writeFirst)
{
int fd = eh->GetFd();
if ((fd < 0) || (fd > GetMaxFds() - 1))
@@ -50,6 +50,8 @@ bool SelectEngine::AddFd(EventHandler* eh)
ref[fd] = eh;
CurrentSetSize++;
+ writeable[eh->GetFd()] = writeFirst;
+
ServerInstance->Logs->Log("SOCKET",DEBUG,"New file descriptor: %d", fd);
return true;
}
@@ -101,16 +103,11 @@ int SelectEngine::DispatchEvents()
/* Populate the select FD set (this is why select sucks compared to epoll, kqueue, IOCP) */
for (std::set<int>::iterator a = fds.begin(); a != fds.end(); a++)
{
- if (ref[*a]->Readable())
- /* Read notifications */
- FD_SET (*a, &rfdset);
- else
- /* Write notifications */
- FD_SET (*a, &wfdset);
-
/* Explicitly one-time writeable */
if (writeable[*a])
FD_SET (*a, &wfdset);
+ else
+ FD_SET (*a, &rfdset);
/* All sockets must receive error notifications regardless */
FD_SET (*a, &errfdset);