summaryrefslogtreecommitdiff
path: root/src/socketengine_kqueue.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/socketengine_kqueue.cpp')
-rw-r--r--src/socketengine_kqueue.cpp24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/socketengine_kqueue.cpp b/src/socketengine_kqueue.cpp
index 0c3226113..14864da79 100644
--- a/src/socketengine_kqueue.cpp
+++ b/src/socketengine_kqueue.cpp
@@ -45,8 +45,9 @@ KQueueEngine::~KQueueEngine()
close(EngineHandle);
}
-bool KQueueEngine::AddFd(int fd, bool readable, char type)
+bool KQueueEngine::AddFd(EventHandler* eh)
{
+ int fd = eh->GetFd();
if ((fd < 0) || (fd > MAX_DESCRIPTORS))
{
ServerInstance->Log(DEFAULT,"ERROR: FD of %d added above max of %d",fd,MAX_DESCRIPTORS);
@@ -61,17 +62,12 @@ bool KQueueEngine::AddFd(int fd, bool readable, char type)
if (ref[fd])
return false;
- ref[fd] = type;
- if (readable)
- {
- ServerInstance->Log(DEBUG,"Set readbit");
- ref[fd] |= X_READBIT;
- }
+ ref[fd] = eh;
ServerInstance->Log(DEBUG,"Add socket %d",fd);
struct kevent ke;
ServerInstance->Log(DEBUG,"kqueue: Add socket to events, kq=%d socket=%d",EngineHandle,fd);
- EV_SET(&ke, fd, readable ? EVFILT_READ : EVFILT_WRITE, EV_ADD, 0, 0, NULL);
+ EV_SET(&ke, fd, eh->Readable() ? EVFILT_READ : EVFILT_WRITE, EV_ADD, 0, 0, NULL);
int i = kevent(EngineHandle, &ke, 1, 0, 0, NULL);
if (i == -1)
{
@@ -83,15 +79,17 @@ bool KQueueEngine::AddFd(int fd, bool readable, char type)
return true;
}
-bool KQueueEngine::DelFd(int fd)
+bool KQueueEngine::DelFd(EventHandler* eh)
{
+ int fd = eh->GetFd();
+
ServerInstance->Log(DEBUG,"KQueueEngine::DelFd(%d)",fd);
if ((fd < 0) || (fd > MAX_DESCRIPTORS))
return false;
struct kevent ke;
- EV_SET(&ke, fd, ref[fd] & X_READBIT ? EVFILT_READ : EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
+ EV_SET(&ke, fd, eh->Readable() ? EVFILT_READ : EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
int i = kevent(EngineHandle, &ke, 1, 0, 0, NULL);
if (i == -1)
{
@@ -100,7 +98,7 @@ bool KQueueEngine::DelFd(int fd)
}
CurrentSetSize--;
- ref[fd] = 0;
+ ref[fd] = NULL;
return true;
}
@@ -114,7 +112,7 @@ int KQueueEngine::GetRemainingFds()
return MAX_DESCRIPTORS - CurrentSetSize;
}
-int KQueueEngine::Wait(int* fdlist)
+int KQueueEngine::Wait(EventHandler** fdlist)
{
int result = 0;
@@ -122,7 +120,7 @@ int KQueueEngine::Wait(int* fdlist)
ts.tv_sec = 0;
int i = kevent(EngineHandle, NULL, 0, &ke_list[0], MAX_DESCRIPTORS, &ts);
for (int j = 0; j < i; j++)
- fdlist[result++] = ke_list[j].ident;
+ fdlist[result++] = ref[ke_list[j].ident];
return result;
}