Skip to content

Commit

Permalink
Not tested yet: Write and read at the same time in kqueue
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5582 e03df62e-2008-0410-955e-edbf42e46eb7
  • Loading branch information
braindigitalis committed Oct 30, 2006
1 parent b27cdbe commit d914755
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/socketengine_kqueue.h
Expand Up @@ -55,6 +55,7 @@ class KQueueEngine : public SocketEngine
virtual bool DelFd(EventHandler* eh);
virtual int DispatchEvents();
virtual std::string GetName();
virtual void WantWrite(EventHandler* eh);
};

/** Creates a SocketEngine
Expand Down
30 changes: 28 additions & 2 deletions src/socketengine_kqueue.cpp
Expand Up @@ -107,6 +107,21 @@ bool KQueueEngine::DelFd(EventHandler* eh)
return true;
}

void KQueueEngine::WantWrite(EventHandler* eh)
{
struct kevent ke;
EV_SET(&ke, eh->GetFd(), EVFILT_WRITE | EVFILT_READ, EV_ADD | EV_ONESHOT, 0, 0, NULL);
int i = kevent(EngineHandle, &ke, 1, 0, 0, NULL);
if (i == -1)
{
ServerInstance->Log(DEBUG,"kqueue: Unable to set fd %d for wanting write", eh->GetFd());
}
else
{
ServerInstance->Log(DEBUG,"kqueue: Set fd %d for want write", eh->GetFd());
}
}

int KQueueEngine::GetMaxFds()
{
return MAX_DESCRIPTORS;
Expand All @@ -124,8 +139,19 @@ int KQueueEngine::DispatchEvents()
int i = kevent(EngineHandle, NULL, 0, &ke_list[0], MAX_DESCRIPTORS, &ts);
for (int j = 0; j < i; j++)
{
ServerInstance->Log(DEBUG,"Handle %s event on fd %d",ref[ke_list[j].ident]->Readable() ? "read" : "write", ref[ke_list[j].ident]->GetFd());
ref[ke_list[j].ident]->HandleEvent(ref[ke_list[j].ident]->Readable() ? EVENT_READ : EVENT_WRITE);
ServerInstance->Log(DEBUG,"Handle %s event on fd %d",ke_list[j].flags & EVFILT_WRITE ? "write" : "read", ke_list[j].ident);
if (ke_list[j].flags & EVFILT_WRITE)
{
ServerInstance->Log(DEBUG,"kqueue: Write socket wants to be set back to read");
struct kevent ke;
EV_SET(&ke, ke_list[j].ident, EVFILT_READ, EV_ADD, 0, 0, NULL);
int i = kevent(EngineHandle, &ke, 1, 0, 0, NULL);
if (i == -1)
{
ServerInstance->Log(DEBUG,"kqueue: Unable to set fd %d back to just wanting to read!", ke_list[j].ident);
}
}
ref[ke_list[j].ident]->HandleEvent(ke_list[j].flags & EVFILT_WRITE ? EVENT_WRITE : EVENT_READ);
}

return i;
Expand Down

0 comments on commit d914755

Please sign in to comment.